Nested documents using solr 6.2.1
hi , i am trying to work on nested documents in solr 6.2.1. I am trying to generate employee info from database. parent node consists of empid,cid,sid,pid. child node consists of price,empid,cid,sid,pid.[multiple prices will be exists, remaining values are same as parent] data-config.xml --- managed-schema -- empid Did full-import, completed successfully. when i used select query, below resonse got. http://localhost:9119/solr/employee/select?q=*:* { "responseHeader": { "status": 0, "QTime": 0, "params": { "q": "*:*", "indent": "on", "rows": "100", "wt": "json", "_": "1496057171982" } }, "response": { "numFound": 3, "start": 0, "docs": [{ "empid": "E1", "cid": "c1", "sid": "s1", "pid": "p1", "price": "123" }, { "empid": "E1", "cid": "c1", "sid": "s1", "pid": "p1", "price": "567" }, { "empid": "E1", "cid": "c1", "sid": "s1", "pid": "p1", "price": "0" } ] } } when i query above, got the childs along with parent.[parent node that is which is having price 'zero']. I don't know how to write the solr query to get the below response. { "responseHeader": { "status": 0, "QTime": 0, "params": { "q": "*:*", "indent": "on", "rows": "100", "wt": "json", "_": "1496057171982" } }, "response": { "numFound": 3, "start": 0, "docs": [{ "empid": "E1", "cid": "c1", "sid": "s1", "pid": "p1", "price": "0", "_childDocuments_": [{ "empid": "E1", "cid": "c1", "sid": "s1", "pid": "p1", "price": "123" }, { "empid": "E1", "cid": "c1", "sid": "s1", "pid": "p1", "price": "567" } ] }] } } Please help me in this. Many thanks in advance. -- View this message in context: http://lucene.472066.n3.nabble.com/Nested-documents-using-solr-6-2-1-tp4338024.html Sent from the Solr - User mailing list archive at Nabble.com.
Re: How to handle nested documents in solr (SolrJ)
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=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F_l=serp.3...34316.37762.0.37969.10.10.0.0.0.0.104.678.9j1.10.00...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)
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=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F_l=serp.3...34316.37762.0.37969.10.10.0.0.0.0.104.678.9j1.10.00...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)
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=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F_l=serp.3...34316.37762.0.37969.10.10.0.0.0.0.104.678.9j1.10.00...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)
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=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F=nested+documents+site%3Amail-archives.apache.org%2Fmod_mbox%2Flucene-solr-user%2F_l=serp.3...34316.37762.0.37969.10.10.0.0.0.0.104.678.9j1.10.00...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.
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: Nested documents in Solr
Hi Ramzi, Thank you but I am not sure to understand well your answer. In your example, I suppose that the indexed docs are flattened. If I want an AND query instead of an OR query (let say, for example 'chapter_title:Lucene AND chapter_content:fun'), how can I be sure that the terms Lucene and fun will be matched in the same chapter of the book? (since in this case chapter_content and chapter_title are multivalued fields)? Regards, Aurélien On 21.10.2014 19:59, Ramzi Alqrainy wrote: I think if I have your question right, You can use multiple custom query syntax. You explicitly specify an alternative query parser such as DisMax or eDisMax, you're using the standard Lucene query parser by default. In your case, I think I can solve it by using this query chapter_title:Introduction ( chapter_title:Lucene OR chapter_content:fun ) Here are some query examples demonstrating the query syntax. *Keyword matching* Search for word foo in the title field. title:foo Search for phrase foo bar in the title field. title:foo bar Search for phrase foo bar in the title field AND the phrase quick fox in the body field. title:foo bar AND body:quick fox Search for either the phrase foo bar in the title field AND the phrase quick fox in the body field, or the word fox in the title field. (title:foo bar AND body:quick fox) OR title:fox Search for word foo and not bar in the title field. title:foo -title:bar *Wildcard matching* Search for any word that starts with foo in the title field. title:foo* Search for any word that starts with foo and ends with bar in the title field. title:foo*bar Note that Lucene doesn't support using a * symbol as the first character of a search. -- View this message in context: http://lucene.472066.n3.nabble.com/Nested-documents-in-Solr-tp4165099p4165232.html Sent from the Solr - User mailing list archive at Nabble.com. Hi, I have question regarding nested document queries: For example, let’s say that I have the following book: Book _title: Nested document for dummies Chapter1_Title: Introduction Chapter1_Content: Nested documents are fun. Chapter2_Title: Which technology should I use? Chapter2_Content: Lucene of course! First I want to find books that contain an introduction and that are about Lucene. So I decide to flatten my data and use 3 multivalued fields (Book_Title,Chapter_Title and Chapter_Content), I index my document and then I get what I want when I use the following query : “ chapter_title:Introduction AND chapter_title:Lucene “ Now I want to find books that contain “fun” in a chapter called “introduction”. My model is no more valid (Chapter2_content is no more linked with Chapter2_title). That is why I change my datamodel and use nested documents: I have now a parent with a single valued field Book_title and different childs with single valued fields Chapter_title and Chapter_Content. Now, when I run the query “chapter_title: Introduction AND chapter_content:fun” I also get what I want… But what do I have to do if I want to use these two kinds of query with a unique data model? Thank you, Regards, Aurélien MAZOYER - To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org
Re: Nested documents in Solr
Hello Aurélien, There are a lot of materials about this problem. Start from this one: https://www.youtube.com/watch?v=YCkkOyZ-zkM On Wed, Oct 22, 2014 at 6:08 PM, aurelien.mazo...@francelabs.com wrote: Hi Ramzi, Thank you but I am not sure to understand well your answer. In your example, I suppose that the indexed docs are flattened. If I want an AND query instead of an OR query (let say, for example 'chapter_title:Lucene AND chapter_content:fun'), how can I be sure that the terms Lucene and fun will be matched in the same chapter of the book? (since in this case chapter_content and chapter_title are multivalued fields)? Regards, Aurélien On 21.10.2014 19:59, Ramzi Alqrainy wrote: I think if I have your question right, You can use multiple custom query syntax. You explicitly specify an alternative query parser such as DisMax or eDisMax, you're using the standard Lucene query parser by default. In your case, I think I can solve it by using this query chapter_title:Introduction ( chapter_title:Lucene OR chapter_content:fun ) Here are some query examples demonstrating the query syntax. *Keyword matching* Search for word foo in the title field. title:foo Search for phrase foo bar in the title field. title:foo bar Search for phrase foo bar in the title field AND the phrase quick fox in the body field. title:foo bar AND body:quick fox Search for either the phrase foo bar in the title field AND the phrase quick fox in the body field, or the word fox in the title field. (title:foo bar AND body:quick fox) OR title:fox Search for word foo and not bar in the title field. title:foo -title:bar *Wildcard matching* Search for any word that starts with foo in the title field. title:foo* Search for any word that starts with foo and ends with bar in the title field. title:foo*bar Note that Lucene doesn't support using a * symbol as the first character of a search. -- View this message in context: http://lucene.472066.n3.nabble.com/Nested-documents- in-Solr-tp4165099p4165232.html Sent from the Solr - User mailing list archive at Nabble.com. Hi, I have question regarding nested document queries: For example, let’s say that I have the following book: Book _title: Nested document for dummies Chapter1_Title: Introduction Chapter1_Content: Nested documents are fun. Chapter2_Title: Which technology should I use? Chapter2_Content: Lucene of course! First I want to find books that contain an introduction and that are about Lucene. So I decide to flatten my data and use 3 multivalued fields (Book_Title,Chapter_Title and Chapter_Content), I index my document and then I get what I want when I use the following query : “ chapter_title:Introduction AND chapter_title:Lucene “ Now I want to find books that contain “fun” in a chapter called “introduction”. My model is no more valid (Chapter2_content is no more linked with Chapter2_title). That is why I change my datamodel and use nested documents: I have now a parent with a single valued field Book_title and different childs with single valued fields Chapter_title and Chapter_Content. Now, when I run the query “chapter_title: Introduction AND chapter_content:fun” I also get what I want… But what do I have to do if I want to use these two kinds of query with a unique data model? Thank you, Regards, Aurélien MAZOYER - To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org -- Sincerely yours Mikhail Khludnev Principal Engineer, Grid Dynamics http://www.griddynamics.com mkhlud...@griddynamics.com
Nested documents in Solr
Hi, I have some question regarding nested document queries. For example, let’s say that I have many books, one of which is the following one: Book _title: Nested documents for dummies Chapter1_Title: Introduction Chapter1_Content: Nested documents are fun. Chapter2_Title: Which technology should I use? Chapter2_Content: Lucene of course! First I want to find books that contain an introduction and that are about Lucene. So I decide to flatten my data and use 3 multivalued fields (Book_Title,Chapter_Title and Chapter_Content), I index my document and then I get what I want when I run the following query : “ chapter_title:Introduction AND chapter_title:Lucene “ But now I want to find books that contain “fun” in a chapter which name is “introduction”. My model is no more valid (Chapter2_content is no more linked with Chapter2_title). That is why I change my datamodel and use nested documents: I now have a parent with a single valued field Book_title and different childs with single valued fields Chapter_title and Chapter_Content. Now, when I run the query “chapter_title: Introduction AND chapter_content:fun” I also get what I want… But what do I have to do if I want to use these two kinds of query with a unique data model? Maybe the only way to do this is to use nested documents and to index data both in child documents and in a flattened form in the parent document. Then we will be able to run the two different queries. Do you have any other (better) idea? Thank you, Regards, Aurélien
Re: Nested documents in Solr
I think if I have your question right, You can use multiple custom query syntax. You explicitly specify an alternative query parser such as DisMax or eDisMax, you're using the standard Lucene query parser by default. In your case, I think I can solve it by using this query chapter_title:Introduction ( chapter_title:Lucene OR chapter_content:fun ) Here are some query examples demonstrating the query syntax. *Keyword matching* Search for word foo in the title field. title:foo Search for phrase foo bar in the title field. title:foo bar Search for phrase foo bar in the title field AND the phrase quick fox in the body field. title:foo bar AND body:quick fox Search for either the phrase foo bar in the title field AND the phrase quick fox in the body field, or the word fox in the title field. (title:foo bar AND body:quick fox) OR title:fox Search for word foo and not bar in the title field. title:foo -title:bar *Wildcard matching* Search for any word that starts with foo in the title field. title:foo* Search for any word that starts with foo and ends with bar in the title field. title:foo*bar Note that Lucene doesn't support using a * symbol as the first character of a search. -- View this message in context: http://lucene.472066.n3.nabble.com/Nested-documents-in-Solr-tp4165099p4165232.html Sent from the Solr - User mailing list archive at Nabble.com.