Hi Stephen, you are welcome, but to give a definitive answer there I think it would be beneficial to fully describe your latest requirement. Is it an AND query across children? i.e. you just want a parent only if its children have both the terms? potentially 1 child one term and another child another?
Cheers -------------------------- Alessandro Benedetti Apache Lucene/Solr Committer Director, R&D Software Engineer, Search Consultant www.sease.io On Tue, 9 Nov 2021 at 17:50, Stephen Lewis Bianamara < stephen.bianam...@gmail.com> wrote: > Alessandro, > > Thank you for your response! In this case AND search will be a requirement, > and I was hoping it would be possible across child docs. It's great to have > the confirmation here that it is indeed not possible without duplicating > data. > > Cheers, > Stephen > > On Mon, Nov 8, 2021 at 10:52 AM Alessandro Benedetti <a.benede...@sease.io > > > wrote: > > > Hi Stephen, > > I have been using nested documents and the various types of join multiple > > times in the past. > > Let's assume you can use the block join. > > First of all you need to follow the indexing approach that aims to index > a > > parent and children within the same block: > > > > https://solr.apache.org/guide/8_10/indexing-nested-documents.html > > > > Then let's see the various use cases you mentioned: > > > > > > *keyword search for /lemon apple/ and onlyreturn the parent;* > > Do you want to match on children and then only return the parents? > > > > > https://solr.apache.org/guide/8_10/other-parsers.html#block-join-parent-query-parser > > > > Do you just want to match the parents? then just run the query on the > > parent field you like and add a 'fq' filtering by the document type > > (fq='type": "post") > > > > * /lemon lime/ and return the parent and comment1;* > > */lemon pear/ and return the parent and comment2;* > > I guess you can achieve this just by running a normal multi-field query, > > for example using the edismax query parser( > > https://solr.apache.org/guide/6_6/the-extended-dismax-query-parser.html) > > and both: > > comment_en and post_en as qf(query fields). > > *N.B.* nested documents are just separate Lucene documents after all, so > > you can retrieve them indepentently of block join query parsers. > > > > > > * /lime pear/ and return the* > > *parent, comment1, and comment2.* > > You go with a > > > > > https://solr.apache.org/guide/8_10/other-parsers.html#block-join-parent-query-parser > > to > > retrieve the parents of fitting children and play with the > > > > > https://solr.apache.org/guide/8_10/transforming-result-documents.html#child-childdoctransformerfactory > > to retrieve the related matching children. > > The easiest approach involves the transformer to just return all > children, > > in your case you may want to play with the childFilter, to only return > > matching children. > > If the transformer won't solve your exact use case, I recommend you > combine > > the parent query parser in OR with a classic query on the children. > > > > > > * And /lime gum/ should return nothing (as ifit were an AND query).* > > For this, I don't think your data model design(nested docs) fits the > > requirement, you may need to flatten the data. > > > > You can find more details about scoring: > > > > > https://solr.apache.org/guide/8_10/other-parsers.html#scoring-with-the-block-join-parent-query-parser > > < > > > https://solr.apache.org/guide/8_10/other-parsers.html#scoring-with-the-block-join-parent-query-parser > > > > > > > Hope this helped! > > > > Cheers > > -------------------------- > > Alessandro Benedetti > > Apache Lucene/Solr Committer > > Director, R&D Software Engineer, Search Consultant > > > > www.sease.io > > > > > > On Wed, 3 Nov 2021 at 20:58, Stephen Lewis Bianamara < > > stephen.bianam...@gmail.com> wrote: > > > > > Hi Folks, > > > > > > Going to give this one more shot. Is there anyone out there who > > understands > > > child docs well enough to answer this basic question? > > > > > > Thanks, > > > Stephen > > > > > > On Fri, Oct 29, 2021 at 2:56 PM Stephen Lewis Bianamara < > > > stephen.bianam...@gmail.com> wrote: > > > > > > > Hi SOLR Community, > > > > > > > > Still hoping for help on this. Is there anyone out there who > > understands > > > > child docs well enough to answer the question of "yes this should > work" > > > or > > > > "no it cannot work"? > > > > > > > > Thanks, > > > > Stephen > > > > > > > > On Wed, Oct 27, 2021 at 8:51 AM Stephen Lewis Bianamara < > > > > stephen.bianam...@gmail.com> wrote: > > > > > > > >> Hi Folks, > > > >> > > > >> Wanted to follow up here. Can someone help me just answer whether > what > > > >> I'm hoping for is feasible? > > > >> > > > >> (a) The desired outcome is supported with the right model/queries > > > >> (b) The desired outcome is not supported; maybe it could be in the > > > future > > > >> (c) The desired outcome is fundamentally unsupportable for the > > > >> foreseeable future > > > >> > > > >> To summarize, the desired behavior is: > > > >> > > > >> - Query which can AND across child docs (i.e, return parents > > > >> whos children match an AND query even if tokens are spread across > > > children) > > > >> - Query whose parents are returned based on relevance of the > children > > > >> > > > >> In my example, obviously there is parent data being queried > > ("post_en"), > > > >> but the parent data could easily be made child data if need be. > > > >> > > > >> Thanks! > > > >> Stephen > > > >> > > > >> On Mon, Oct 25, 2021 at 6:54 AM Stephen Lewis Bianamara < > > > >> stephen.bianam...@gmail.com> wrote: > > > >> > > > >>> Hi SOLR Community, > > > >>> > > > >>> I'm experimenting with solr 8.10 and trying to get a query pattern > > with > > > >>> child docs to work. An example of a nested document structure I'd > > like > > > to > > > >>> search is below. In this example, there will only be two levels, > > child > > > of > > > >>> type:post and /comments children. > > > >>> { > > > >>> "id": "post1", > > > >>> "type": "post", > > > >>> "post_en": "I put lemon on my apple slices to keep them fresh", > > > >>> "comments": [ > > > >>> { > > > >>> "id": "comment1", > > > >>> "type": "comment", > > > >>> "comment_en": "Lime works too" > > > >>> }, > > > >>> { > > > >>> "id": "comment2", > > > >>> "type": "comment", > > > >>> "comment_en": "Does it work for pears?" > > > >>> } > > > >>> ] > > > >>> } > > > >>> > > > >>> What I'd like is to be able to do keyword search for /lemon apple/ > > and > > > >>> only return the parent; /lemon lime/ and return the parent and > > > comment1; > > > >>> /lemon pear/ and return the parent and comment2; /lime pear/ and > > > return the > > > >>> parent, comment1, and comment2. And /lime gum/ should return > nothing > > > (as if > > > >>> it were an AND query). Additionally, this should all be done with > > > relevance. > > > >>> > > > >>> I've tried a few combinations of nested docs from this > documentation > > > >>> < > https://solr.apache.org/guide/8_10/searching-nested-documents.html > > >, > > > >>> but am having trouble getting this to work. I wonder if I'm asking > > more > > > >>> from block join/child doc transformer than it currently supports, > or > > > >>> perhaps I'm just missing something. Can someone familiar with > nesting > > > >>> documents help me out? I've included my schema below as well. > > > >>> > > > >>> Thanks! > > > >>> Stephen > > > >>> > > > >>> <?xml version="1.0" encoding="UTF-8" ?> > > > >>> <schema name="ChildTest" version="1.5"> > > > >>> <fields> > > > >>> <field name="id" type="string" required="true" > docValues="true"/> > > > >>> <dynamicField name="*_en" type="text_en" large="true" > > > >>> omitNorms="true" /> > > > >>> <field name="username" type="string" docValues="true" /> > > > >>> <field name="type" type="string" docValues="true" /> > > > >>> <field name="_version_" type="long" /> > > > >>> <!-- child docs --> > > > >>> <field name="_root_" type="string" indexed="true" > stored="false" > > > >>> docValues="false" /> > > > >>> <field name="_nest_path_" type="_nest_path_" /> > > > >>> <field name="_nest_parent_" type="string" indexed="true" > > > >>> stored="true" /> > > > >>> </fields> > > > >>> <uniqueKey>id</uniqueKey> > > > >>> <types> > > > >>> <fieldType name="_nest_path_" class="solr.NestPathField" /> > > > >>> <fieldType name="long" class="solr.LongPointField" /> > > > >>> <fieldType name="string" class="solr.StrField" > > > >>> sortMissingLast="true" /> > > > >>> <fieldType name="text_en" class="solr.TextField" > > > >>> positionIncrementGap="100" autoGeneratePhraseQueries="true"> > > > >>> <analyzer type="index"> > > > >>> <tokenizer class="solr.WhitespaceTokenizerFactory"/> > > > >>> <filter class="solr.LowerCaseFilterFactory"/> > > > >>> <filter class="solr.SnowballPorterFilterFactory"/> > > > >>> </analyzer> > > > >>> <analyzer type="query"> > > > >>> <tokenizer class="solr.WhitespaceTokenizerFactory"/> > > > >>> <filter class="solr.LowerCaseFilterFactory"/> > > > >>> <filter class="solr.SnowballPorterFilterFactory"/> > > > >>> </analyzer> > > > >>> </fieldType> > > > >>> </types> > > > >>> </schema> > > > >>> > > > >> > > > > > >