Akash Sethi
Akash Sethi

Reputation: 2294

Solr nested Object Parse Error

I have a nested object in Solr and i am using Schema in manage schema file. But Solr Storing the nested object in flat manner.

Example :-

{ "id": 1234,
  "name":{
           "fname":"Random",
           "lastName":"Name"
          }
}

manage-schema file

<field name="id" type="int" indexed="true" stored="true" required="true" multiValued="false" />
<field name="name" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="name.fName" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="name.lastName" type="string" indexed="true" stored="true" required="true" multiValued="false" />

When is Insert sample data in Solr it Storing data as this

{"id":1234,
"name.fName":"Random",
"name.lastName":"Name"
}

So when i get the data from solr and try to convert to my class object then it is giving me parse error no value for key fName

Please help Thanks

Upvotes: 1

Views: 358

Answers (1)

Alessandro Benedetti
Alessandro Benedetti

Reputation: 1114

There are 2 main possible approaches in modelling/querying nested objects in Solr : Index Time Join

  • Imply a very specific indexing strategy, you must index an entire block ( children + parent)

  • quite fast

Query Time Join

  • you don't need to follow any particular indexing strategy, eveything will happen at query time.
  • 'slow'

In both these scenarios you don't need any fancy way of naming your fields in the schema ( the nested object functionality has nothing to do with field naming).

[1] https://cwiki.apache.org/confluence/display/solr/Uploading+Data+with+Index+Handlers#UploadingDatawithIndexHandlers-NestedChildDocuments

Upvotes: 0

Related Questions