How to Created Nested JSON objects in SOLR?

Viewed 1336

I am dumping data in SOLR database. Earlier I was using Elastic Search and it was allowing me to store nested JSON objects.

Is there any way I can dynamically create nested JSON values when inserting in SOLR?

I am using JAVA as a backend language. My code is:

SolrInputDocument document = new SolrInputDocument();
document.addField("UUID", eventID);
document.addField("eventCategory", eventCategory);
.
.
.
.
document.addField("source", source);

I want something like this: 
{
"UUID":"1",
"source":abcd,
"eventCategory": {
    "event1":"a",
    "event2":"b",
    "event3":"c"
 }
}
2 Answers

you can use addChildDocument to add the nested doc to the parent one. So code would be:

SolrInputDocument document = new SolrInputDocument();
document.addField("UUID", eventID);
document.addField("eventCategory", eventCategory);
...
SolrInputDocument child = new SolrInputDocument();
...
document.addChildDocument(child);
Related