You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Vikash Sharma <vi...@gmail.com> on 2012/11/30 16:38:47 UTC

Solr 4: Join Query

Hi All,
I have my field definition in schema.xml like below

<field name="id" type="string" indexed="true"..... />
<field name="Emp_id" type="string" indexed="true"..... />
<field name="doc_id" type="string" indexed="true"..... />
<field name="content" type="string" indexed="true"..... />


I need to create separate record in solr for each parent child
relationship... such that if child is same across different parent that it
gets stored only once.

For e.g.
 -----------_Record 1
<id>ABC<id/>
<emp_id>EMP001<emp_id/>
<doc_id>DOC001<doc_id/>
<doc_content>My Parent Doc<doc_content/>

 -----------_Record 2
<id>DOC001<id/>
<emp_id><emp_id/>
<doc_id><doc_id/>
<doc_content>My Document Data<doc_content/>


This will ensure that if any doc_id content is duplicate, than only once
the record is inserted in the solr.

Lastly, I want the result as join. if emp_id=EMP001. then both record
should be returned, as there is a relationship between two records using of
doc_id = id

If I query:
http://localhost:8983/solr/select?q={!join%20from=doc_id%20to=id}emp_id:EMP001&wt=json<http://localhost:8983/solr/select?q={!join%20from=sha_one%20to=id}project_id:10&wt=json>

I expect both record should be returned either one after another or
nested..
But I only get child records...


Please help..



Regards,
Vikash Sharma
vikash0810@gmail.com

Re: Solr 4: Join Query

Posted by Erick Erickson <er...@gmail.com>.
not that I know of. Also, your performance will be much better if you can
denormlized the data.


On Mon, Dec 3, 2012 at 12:44 AM, Vikash Sharma <vi...@gmail.com> wrote:

> Hi Erick,
> One more thing: So is there any other way to get the result?
> I mean, I need to get both parent and child document in/not nested format.
>
> Regards,
> Vikash
>
> Regards,
> Vikash Sharma
> vikash0810@gmail.com
>
>
> On Sat, Dec 1, 2012 at 10:29 PM, Erick Erickson <erickerickson@gmail.com
> >wrote:
>
> > That's the way joins work, and why they're called "pseudo join", they
> don't
> > work like DB joins and return data from both records....
> >
> > Joins were put in for a specific use-case, when you try to treat Solr
> like
> > a DB you're bound to be disappointed. I'd think about reworking the
> > solution to de-normalize the data so you don't have to do joins.
> >
> > Best
> > Erick
> >
> >
> > On Fri, Nov 30, 2012 at 10:38 AM, Vikash Sharma <vikash0810@gmail.com
> > >wrote:
> >
> > > Hi All,
> > > I have my field definition in schema.xml like below
> > >
> > > <field name="id" type="string" indexed="true"..... />
> > > <field name="Emp_id" type="string" indexed="true"..... />
> > > <field name="doc_id" type="string" indexed="true"..... />
> > > <field name="content" type="string" indexed="true"..... />
> > >
> > >
> > > I need to create separate record in solr for each parent child
> > > relationship... such that if child is same across different parent that
> > it
> > > gets stored only once.
> > >
> > > For e.g.
> > >  -----------_Record 1
> > > <id>ABC<id/>
> > > <emp_id>EMP001<emp_id/>
> > > <doc_id>DOC001<doc_id/>
> > > <doc_content>My Parent Doc<doc_content/>
> > >
> > >  -----------_Record 2
> > > <id>DOC001<id/>
> > > <emp_id><emp_id/>
> > > <doc_id><doc_id/>
> > > <doc_content>My Document Data<doc_content/>
> > >
> > >
> > > This will ensure that if any doc_id content is duplicate, than only
> once
> > > the record is inserted in the solr.
> > >
> > > Lastly, I want the result as join. if emp_id=EMP001. then both record
> > > should be returned, as there is a relationship between two records
> using
> > of
> > > doc_id = id
> > >
> > > If I query:
> > >
> > >
> >
> http://localhost:8983/solr/select?q={!join%20from=doc_id%20to=id}emp_id:EMP001&wt=json
> > > <
> > >
> >
> http://localhost:8983/solr/select?q={!join%20from=sha_one%20to=id}project_id:10&wt=json
> > > >
> > >
> > > I expect both record should be returned either one after another or
> > > nested..
> > > But I only get child records...
> > >
> > >
> > > Please help..
> > >
> > >
> > >
> > > Regards,
> > > Vikash Sharma
> > > vikash0810@gmail.com
> > >
> >
>

Re: Solr 4: Join Query

Posted by Vikash Sharma <vi...@gmail.com>.
Hi Erick,
One more thing: So is there any other way to get the result?
I mean, I need to get both parent and child document in/not nested format.

Regards,
Vikash

Regards,
Vikash Sharma
vikash0810@gmail.com


On Sat, Dec 1, 2012 at 10:29 PM, Erick Erickson <er...@gmail.com>wrote:

> That's the way joins work, and why they're called "pseudo join", they don't
> work like DB joins and return data from both records....
>
> Joins were put in for a specific use-case, when you try to treat Solr like
> a DB you're bound to be disappointed. I'd think about reworking the
> solution to de-normalize the data so you don't have to do joins.
>
> Best
> Erick
>
>
> On Fri, Nov 30, 2012 at 10:38 AM, Vikash Sharma <vikash0810@gmail.com
> >wrote:
>
> > Hi All,
> > I have my field definition in schema.xml like below
> >
> > <field name="id" type="string" indexed="true"..... />
> > <field name="Emp_id" type="string" indexed="true"..... />
> > <field name="doc_id" type="string" indexed="true"..... />
> > <field name="content" type="string" indexed="true"..... />
> >
> >
> > I need to create separate record in solr for each parent child
> > relationship... such that if child is same across different parent that
> it
> > gets stored only once.
> >
> > For e.g.
> >  -----------_Record 1
> > <id>ABC<id/>
> > <emp_id>EMP001<emp_id/>
> > <doc_id>DOC001<doc_id/>
> > <doc_content>My Parent Doc<doc_content/>
> >
> >  -----------_Record 2
> > <id>DOC001<id/>
> > <emp_id><emp_id/>
> > <doc_id><doc_id/>
> > <doc_content>My Document Data<doc_content/>
> >
> >
> > This will ensure that if any doc_id content is duplicate, than only once
> > the record is inserted in the solr.
> >
> > Lastly, I want the result as join. if emp_id=EMP001. then both record
> > should be returned, as there is a relationship between two records using
> of
> > doc_id = id
> >
> > If I query:
> >
> >
> http://localhost:8983/solr/select?q={!join%20from=doc_id%20to=id}emp_id:EMP001&wt=json
> > <
> >
> http://localhost:8983/solr/select?q={!join%20from=sha_one%20to=id}project_id:10&wt=json
> > >
> >
> > I expect both record should be returned either one after another or
> > nested..
> > But I only get child records...
> >
> >
> > Please help..
> >
> >
> >
> > Regards,
> > Vikash Sharma
> > vikash0810@gmail.com
> >
>

Re: Solr 4: Join Query

Posted by Erick Erickson <er...@gmail.com>.
That's the way joins work, and why they're called "pseudo join", they don't
work like DB joins and return data from both records....

Joins were put in for a specific use-case, when you try to treat Solr like
a DB you're bound to be disappointed. I'd think about reworking the
solution to de-normalize the data so you don't have to do joins.

Best
Erick


On Fri, Nov 30, 2012 at 10:38 AM, Vikash Sharma <vi...@gmail.com>wrote:

> Hi All,
> I have my field definition in schema.xml like below
>
> <field name="id" type="string" indexed="true"..... />
> <field name="Emp_id" type="string" indexed="true"..... />
> <field name="doc_id" type="string" indexed="true"..... />
> <field name="content" type="string" indexed="true"..... />
>
>
> I need to create separate record in solr for each parent child
> relationship... such that if child is same across different parent that it
> gets stored only once.
>
> For e.g.
>  -----------_Record 1
> <id>ABC<id/>
> <emp_id>EMP001<emp_id/>
> <doc_id>DOC001<doc_id/>
> <doc_content>My Parent Doc<doc_content/>
>
>  -----------_Record 2
> <id>DOC001<id/>
> <emp_id><emp_id/>
> <doc_id><doc_id/>
> <doc_content>My Document Data<doc_content/>
>
>
> This will ensure that if any doc_id content is duplicate, than only once
> the record is inserted in the solr.
>
> Lastly, I want the result as join. if emp_id=EMP001. then both record
> should be returned, as there is a relationship between two records using of
> doc_id = id
>
> If I query:
>
> http://localhost:8983/solr/select?q={!join%20from=doc_id%20to=id}emp_id:EMP001&wt=json
> <
> http://localhost:8983/solr/select?q={!join%20from=sha_one%20to=id}project_id:10&wt=json
> >
>
> I expect both record should be returned either one after another or
> nested..
> But I only get child records...
>
>
> Please help..
>
>
>
> Regards,
> Vikash Sharma
> vikash0810@gmail.com
>