>
> Interestingly, I was forced to add children as an array even when the
> child was alone and the field was already marked multivalued. It seems
> the code does not do conversation to multi-value type, which means the
> query code has to be a lot more careful about checking field return
> type and having multi-path handling. That's not what Solr does for
> string class (tested). Is that a known issue?
>
> https://github.com/arafalov/SolrJTest/blob/master/src/com/solrstart/solrj/Main.java#L88-L89

Not sure about this. Maybe we might need to check in Dev list or Slack

 If I switch commented/uncommented lines around, the retrieval will fail
> part way through, because one 'children' field is returned as array, but
> not the other one:

This might be because of these checks
https://github.com/apache/lucene-solr/blob/e1392c74400d74366982ccb796063ffdcef08047/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformer.java#L201-L209
but
not sure

Regards,
Munendra S N



On Sun, Aug 23, 2020 at 7:53 PM Alexandre Rafalovitch <arafa...@gmail.com>
wrote:

> Thank you Nunedra,
>
> That was very helpful. I am looking forward to that documentation Jira
> to be merged into the next release.
>
> I was able to get the example working by switching away from anonymous
> children to the field approach. Which means hasChildren() call also
> did not work. It seems the addChildren/hasChildren will need a
> different schema, without _nest_path_ defined. I did not test.
>
> Interestingly, I was forced to add children as an array even when the
> child was alone and the field was already marked multivalued. It seems
> the code does not do conversation to multi-value type, which means the
> query code has to be a lot more careful about checking field return
> type and having multi-path handling. That's not what Solr does for
> string class (tested). Is that a known issue?
>
> https://github.com/arafalov/SolrJTest/blob/master/src/com/solrstart/solrj/Main.java#L88-L89
>
> If I switch commented/uncommented lines around, the retrieval will
> fail part way through, because one 'children' field is returned as
> array, but not the other one:
>
> {responseHeader={status=0,QTime=0,params={q=id:p1,fl=*,[child],wt=javabin,version=2}},response={numFound=1,numFoundExact=true,start=0,docs=[SolrDocument{id=p1,
> name=[parent1], class=[foo.bar.parent1.1, foo.bar.parent1.2],
> _version_=1675826293154775040, children=[SolrDocument{id=c1,
> name=[child1], class=[foo.bar.child1], _version_=1675826293154775040,
> children=SolrDocument{id=gc1, name=[grandChild1],
> class=[foo.bar.grandchild1], _version_=1675826293154775040}},
> SolrDocument{id=c2, name=[child2], class=[foo.bar.child2],
> _version_=1675826293154775040}]}]}}
>
> Regards,
>    Alex.
>
> On Sun, 23 Aug 2020 at 01:38, Munendra S N <sn.munendr...@gmail.com>
> wrote:
> >
> > Hi Alex,
> >
> > Currently, Fixing the documentation for nested docs is under progress.
> More
> > context is available in this JIRA -
> > https://issues.apache.org/jira/browse/SOLR-14383.
> >
> >
> https://github.com/arafalov/SolrJTest/blob/master/src/com/solrstart/solrj/Main.java
> >
> > The child doc transformer needs to be specified as part of the fl
> parameter
> > like fl=*,[child] so that the descendants are returned for each matching
> > doc. As the query q=* matches all the documents, they are returned. If
> only
> > parent doc needs to be returned with descendants then, we should either
> use
> > block join query or query clause which matches only parent doc.
> >
> > Another thing I noticed in the code is that the child docs are indexed as
> > anonymous docs (similar to old syntax) instead of indexing them in the
> new
> > syntax. With this, the nested block will be indexed but since the schema
> > has _nested_path_ defined [child] doc transformer won't return any docs.
> > Anonymous child docs need parentFilter but specifying parentFilter with
> > _nested_path_ will lead to error
> > It is due to this check -
> >
> https://github.com/apache/lucene-solr/blob/1c8f4c988a07b08f83d85e27e59b43eed5e2ca2a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java#L104
> >
> > Instead of indexing the docs this way,
> >
> > > SolrInputDocument parent1 = new SolrInputDocument();
> > > parent1.addField("id", "p1");
> > > parent1.addField("name", "parent1");
> > > parent1.addField("class", "foo.bar.parent1");
> > >
> > > SolrInputDocument child1 = new SolrInputDocument();
> > >
> > > parent1.addChildDocument(child1);
> > > child1.addField("id", "c1");
> > > child1.addField("name", "child1");
> > > child1.addField("class", "foo.bar.child1");
> > >
> > >
> > modify it to indexing
> >
> > > SolrInputDocument parent1 = new SolrInputDocument();
> > > parent1.addField("id", "p1");
> > > parent1.addField("name", "parent1");
> > > parent1.addField("class", "foo.bar.parent1");
> > >
> > > SolrInputDocument child1 = new SolrInputDocument();
> > >
> > > parent1.addField("sometag", Arrays.asList(child1));
> > > child1.addField("id", "c1");
> > > child1.addField("name", "child1");
> > > child1.addField("class", "foo.bar.child1");
> > >
> > > I think, once the documentation fixes get merged to master, indexing
> and
> > searching with the nested documents will become much clearer.
> >
> > Regards,
> > Munendra S N
> >
> >
> >
> > On Sun, Aug 23, 2020 at 5:18 AM Alexandre Rafalovitch <
> arafa...@gmail.com>
> > wrote:
> >
> > > Hello,
> > >
> > > I am trying to get up to date with both SolrJ and Nested Document
> > > implementation and not sure where I am failing with a basic test
> > > (
> > >
> https://github.com/arafalov/SolrJTest/blob/master/src/com/solrstart/solrj/Main.java
> > > ).
> > >
> > > I am using Solr 8.6.1 with a core created with bin/solr create -c
> > > solrj (schemaless is still on).
> > >
> > > I then index a nested parent/child/grandchild document in and then
> > > query it back. Looking at debug it seems to go out fine as a nested
> > > doc but come back as a 3 individual ones.
> > >
> > > Output is:
> > > SolrInputDocument(fields: [id=p1, name=parent1,
> > > class=foo.bar.parent1], children: [SolrInputDocument(fields: [id=c1,
> > > name=child1, class=foo.bar.child1], children:
> > > [SolrInputDocument(fields: [id=gc1, name=grandChild1,
> > > class=foo.bar.grandchild1])])])
> > >
> > >
> {responseHeader={status=0,QTime=1,params={q=*,wt=javabin,version=2}},response={numFound=3,numFoundExact=true,start=0,docs=[SolrDocument{id=gc1,
> > > name=[grandChild1], class=[foo.bar.grandchild1],
> > > _version_=1675769219435724800}, SolrDocument{id=c1, name=[child1],
> > > class=[foo.bar.child1], _version_=1675769219435724800},
> > > SolrDocument{id=p1, name=[parent1], class=[foo.bar.parent1],
> > > _version_=1675769219435724800}]}}
> > > Found 3 documents
> > >
> > > Field: 'id' => 'gc1'
> > > Field: 'name' => '[grandChild1]'
> > > Field: 'class' => '[foo.bar.grandchild1]'
> > > Field: '_version_' => '1675769219435724800'
> > > Children: false
> > >
> > > Field: 'id' => 'c1'
> > > Field: 'name' => '[child1]'
> > > Field: 'class' => '[foo.bar.child1]'
> > > Field: '_version_' => '1675769219435724800'
> > > Children: false
> > >
> > > Field: 'id' => 'p1'
> > > Field: 'name' => '[parent1]'
> > > Field: 'class' => '[foo.bar.parent1]'
> > > Field: '_version_' => '1675769219435724800'
> > > Children: false
> > >
> > > Looking in Admin UI:
> > > * _root_ element is there and has 3 instances of 'p1' value
> > > * _nest_path_ (of type _nest_path_ !?!) is also there but is not
> populated
> > > * _nest_parent_ is not there
> > >
> > > I am not quite sure what that means and what other scheme modification
> > > (to the _default_) I need to do to get it to work.
> > >
> > > I also tried to reproduce the example in the documentation (e.g.
> > >
> https://lucene.apache.org/solr/guide/8_6/indexing-nested-documents.html
> > > and
> > >
> https://lucene.apache.org/solr/guide/8_6/searching-nested-documents.html#searching-nested-documents
> > > )
> > > but both seem to also want some undiscussed schema (e.g. with ID field
> > > instead of id) and fail to execute against default schema.
> > >
> > > I am kind of stuck. Anybody has a working SolrJ/Nested example or
> > > ideas of what I missed.
> > >
> > > Regards,
> > >    Alex.
> > >
>

Reply via email to