You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@solr.apache.org by ufuk yılmaz <uy...@vivaldi.net.INVALID> on 2021/04/20 18:17:04 UTC

Can someone give an example schema for nested document indexing?

Hi,

I’m using SolrCloud version 8.4. I’m having trouble getting nested document indexing and querying work. Can anyone give a basic schema for the example data in Solr documentation:

{
    "ID": "1",
    "title": "Cooking Recommendations",
    "tags": ["cooking", "meetup"],
    "posts": [{
        "ID": "2",
        "title": "Cookies",
        "comments": [{
            "ID": "3",
            "content": "Lovely recipe"
          },
          {
            "ID": "4",
            "content": "A-"
          }
        ]
      },
      {
        "ID": "5",
        "title": "Cakes"
      }
    ]
  }

All examples on the internet are talking about how to index such a document but none of them give a sample schema file like it’s a closely guarded mystery. I tried many different schemas for hours but closest I came was something like:

...
<fieldType name="nest_path" class="solr.NestPathField" indexed="true" stored="true" docValues="true"/>
<field name="comments" type="nest_path" multiValued=”true”>
  <field name=”content” type=”text_general”/>
</field>
...
Which I’m guessing is NOT  correct, because it just returns “comments” field as an array of string, not JSON.

I also tried not specifying child document names (comments) in the schema, as suggested in docs. If I don’t specify ID field in comments, I get a “undefined field” error with comments. If I specify ID’s for each comment, the document gets indexed succesfully but when queried it doesn’t return any child documents with q=*:* and fl=*,[child] 

Sent from Mail for Windows 10