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