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 prasad chowdary <pr...@gmail.com> on 2017/05/24 06:53:31 UTC

How to handle nested documents in solr (SolrJ)

Dear All,

I have a requirement that I need to index the documents in solr using Java
code.

Each document contains a sub documents like below ( Its just for
underastanding my question).


student id : 123
student name : john
marks : 
       maths: 90
       English :95

student id : 124
student name : rack
marks : 
       maths: 80
       English :96

etc...

So, as shown above each document contains one child document i.e marks.

Actaully I don't need any joins or anything.My requirement is :

if I query "English:95" ,it should return the complete document ,i.e child
along with parent like below

student id : 123
student name : john
marks : 
       maths: 90
       English :95

and also if I query "student id : 123" , it should return the whole document
same as above.

Currently I am able to get the child along with parent for child match by
using extendedResults option .

But not able to get the child for parent match.

Please help me out in this regard.Thanks in advance.








--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-handle-nested-documents-in-solr-SolrJ-tp4336861.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: How to handle nested documents in solr (SolrJ)

Posted by Rick Leir <rl...@leirtech.com>.
David,

The articles by Yonick were written around the time that he and others 
were developing the features. This one 
http://yonik.com/solr-nested-objects/ says 5.3 and later. Considering 
that development and bugfixes spanned several versions, you would do 
well to test your configuration with your preferred Solr version and 
upgrade as necessary / desired.

cheers -- Rick


On 2017-05-25 01:45 AM, David Lee wrote:
> Hi Rick,
>
> Adding to this subject, I do appreciate you pointing us to these 
> articles, but I'm curious about how much of these take into account 
> the latest versions of Solr (ie: +6.5 and 7) given the JSON split 
> capabilities, etc. I know that is just on the indexing side so the 
> searches may be the same but things are changing quickly these days 
> (not a bad thing).
>
> Thanks,
>
> David
>
>
> On 5/24/2017 4:26 AM, Rick Leir wrote:
>> Prasad,
>>
>> Gee, you get confusion from a google search for:
>>
>>     nested documents 
>> site:mail-archives.apache.org/mod_mbox/lucene-solr-user/
>>
>> https://www.google.ca/search?safe=strict&q=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F&oq=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F&gs_l=serp.3...34316.37762.0.37969.10.10.0.0.0.0.104.678.9j1.10.0....0...1.1.64.serp..0.0.0.JTf887wWCDM 
>>
>>
>> But my recent posting might help: " Yonick has some good blogs on this."
>>
>> And Mikhail has an excellent blog:
>>
>> https://blog.griddynamics.com/how-to-use-block-join-to-improve-search-efficiency-with-nested-documents-in-solr 
>>
>>
>> cheers -- Rick
>>
>> On 2017-05-24 02:53 AM, prasad chowdary wrote:
>>> Dear All,
>>>
>>> I have a requirement that I need to index the documents in solr 
>>> using Java
>>> code.
>>>
>>> Each document contains a sub documents like below ( Its just for
>>> underastanding my question).
>>>
>>>
>>> student id : 123
>>> student name : john
>>> marks :
>>>         maths: 90
>>>         English :95
>>>
>>> student id : 124
>>> student name : rack
>>> marks :
>>>         maths: 80
>>>         English :96
>>>
>>> etc...
>>>
>>> So, as shown above each document contains one child document i.e marks.
>>>
>>> Actaully I don't need any joins or anything.My requirement is :
>>>
>>> if I query "English:95" ,it should return the complete document ,i.e 
>>> child
>>> along with parent like below
>>>
>>> student id : 123
>>> student name : john
>>> marks :
>>>         maths: 90
>>>         English :95
>>>
>>> and also if I query "student id : 123" , it should return the whole 
>>> document
>>> same as above.
>>>
>>> Currently I am able to get the child along with parent for child 
>>> match by
>>> using extendedResults option .
>>>
>>> But not able to get the child for parent match.
>>
>>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>


Re: How to handle nested documents in solr (SolrJ)

Posted by David Lee <ni...@comcast.net>.
Hi Rick,

Adding to this subject, I do appreciate you pointing us to these 
articles, but I'm curious about how much of these take into account the 
latest versions of Solr (ie: +6.5 and 7) given the JSON split 
capabilities, etc. I know that is just on the indexing side so the 
searches may be the same but things are changing quickly these days (not 
a bad thing).

Thanks,

David


On 5/24/2017 4:26 AM, Rick Leir wrote:
> Prasad,
>
> Gee, you get confusion from a google search for:
>
>     nested documents 
> site:mail-archives.apache.org/mod_mbox/lucene-solr-user/
>
> https://www.google.ca/search?safe=strict&q=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F&oq=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F&gs_l=serp.3...34316.37762.0.37969.10.10.0.0.0.0.104.678.9j1.10.0....0...1.1.64.serp..0.0.0.JTf887wWCDM 
>
>
> But my recent posting might help: " Yonick has some good blogs on this."
>
> And Mikhail has an excellent blog:
>
> https://blog.griddynamics.com/how-to-use-block-join-to-improve-search-efficiency-with-nested-documents-in-solr 
>
>
> cheers -- Rick
>
> On 2017-05-24 02:53 AM, prasad chowdary wrote:
>> Dear All,
>>
>> I have a requirement that I need to index the documents in solr using 
>> Java
>> code.
>>
>> Each document contains a sub documents like below ( Its just for
>> underastanding my question).
>>
>>
>> student id : 123
>> student name : john
>> marks :
>>         maths: 90
>>         English :95
>>
>> student id : 124
>> student name : rack
>> marks :
>>         maths: 80
>>         English :96
>>
>> etc...
>>
>> So, as shown above each document contains one child document i.e marks.
>>
>> Actaully I don't need any joins or anything.My requirement is :
>>
>> if I query "English:95" ,it should return the complete document ,i.e 
>> child
>> along with parent like below
>>
>> student id : 123
>> student name : john
>> marks :
>>         maths: 90
>>         English :95
>>
>> and also if I query "student id : 123" , it should return the whole 
>> document
>> same as above.
>>
>> Currently I am able to get the child along with parent for child 
>> match by
>> using extendedResults option .
>>
>> But not able to get the child for parent match.
>
>


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


Re: How to handle nested documents in solr (SolrJ)

Posted by Erick Erickson <er...@gmail.com>.
I would ask if you need nested documents at all. If you can denormlize
the docs it's often much easier. In your case I can think of several
options:
1> just index a separate field for each subject. Solr handles a couple
of hundred fields with ease.
student id : 123
student name : john
maths: 90
English :95

student id : 123
student name : john
marks: math_90 english_95

You have one "marks" field and each token has it's associated score.
Probably want to left-pad if you want to do range queries here, i.e.
math_009, math_098, math_100. That way you can express [math_009 TO
math_020] and have it "do the right thing".

Use payloads for the scores.

Best,
Erick

On Wed, May 24, 2017 at 2:26 AM, Rick Leir <rl...@leirtech.com> wrote:
> Prasad,
>
> Gee, you get confusion from a google search for:
>
>     nested documents
> site:mail-archives.apache.org/mod_mbox/lucene-solr-user/
>
> https://www.google.ca/search?safe=strict&q=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F&oq=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F&gs_l=serp.3...34316.37762.0.37969.10.10.0.0.0.0.104.678.9j1.10.0....0...1.1.64.serp..0.0.0.JTf887wWCDM
>
> But my recent posting might help: " Yonick has some good blogs on this."
>
> And Mikhail has an excellent blog:
>
> https://blog.griddynamics.com/how-to-use-block-join-to-improve-search-efficiency-with-nested-documents-in-solr
>
> cheers -- Rick
>
>
> On 2017-05-24 02:53 AM, prasad chowdary wrote:
>>
>> Dear All,
>>
>> I have a requirement that I need to index the documents in solr using Java
>> code.
>>
>> Each document contains a sub documents like below ( Its just for
>> underastanding my question).
>>
>>
>> student id : 123
>> student name : john
>> marks :
>>         maths: 90
>>         English :95
>>
>> student id : 124
>> student name : rack
>> marks :
>>         maths: 80
>>         English :96
>>
>> etc...
>>
>> So, as shown above each document contains one child document i.e marks.
>>
>> Actaully I don't need any joins or anything.My requirement is :
>>
>> if I query "English:95" ,it should return the complete document ,i.e child
>> along with parent like below
>>
>> student id : 123
>> student name : john
>> marks :
>>         maths: 90
>>         English :95
>>
>> and also if I query "student id : 123" , it should return the whole
>> document
>> same as above.
>>
>> Currently I am able to get the child along with parent for child match by
>> using extendedResults option .
>>
>> But not able to get the child for parent match.
>
>

Re: How to handle nested documents in solr (SolrJ)

Posted by Rick Leir <rl...@leirtech.com>.
Prasad,

Gee, you get confusion from a google search for:

     nested documents 
site:mail-archives.apache.org/mod_mbox/lucene-solr-user/

https://www.google.ca/search?safe=strict&q=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F&oq=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F&gs_l=serp.3...34316.37762.0.37969.10.10.0.0.0.0.104.678.9j1.10.0....0...1.1.64.serp..0.0.0.JTf887wWCDM

But my recent posting might help: " Yonick has some good blogs on this."

And Mikhail has an excellent blog:

https://blog.griddynamics.com/how-to-use-block-join-to-improve-search-efficiency-with-nested-documents-in-solr

cheers -- Rick

On 2017-05-24 02:53 AM, prasad chowdary wrote:
> Dear All,
>
> I have a requirement that I need to index the documents in solr using Java
> code.
>
> Each document contains a sub documents like below ( Its just for
> underastanding my question).
>
>
> student id : 123
> student name : john
> marks :
>         maths: 90
>         English :95
>
> student id : 124
> student name : rack
> marks :
>         maths: 80
>         English :96
>
> etc...
>
> So, as shown above each document contains one child document i.e marks.
>
> Actaully I don't need any joins or anything.My requirement is :
>
> if I query "English:95" ,it should return the complete document ,i.e child
> along with parent like below
>
> student id : 123
> student name : john
> marks :
>         maths: 90
>         English :95
>
> and also if I query "student id : 123" , it should return the whole document
> same as above.
>
> Currently I am able to get the child along with parent for child match by
> using extendedResults option .
>
> But not able to get the child for parent match.