0

In solr 6.6.0, I want to use nested objects for particular key.

So suppose, I have one document as follows :

{
    "ID": "16_nl",
    "countryIso": "AUS",
    "regionId": 30,
    "name": "test",
    "placeId": 50,
    "eventID": 100,
    "facilities": [12],
    "created": "2017-11-30T11:00:36.717Z",
    "modified": "2017-11-30T11:00:36.717Z"
}

But now, I want to add child document inside above document with key "proposal" as follows

{
    "ID": "16_nl",
    "countryIso": "AUS",
    "regionId": 30,
    "name": "test",
    "placeId": 50,
    "eventID": 100,
    "facilities": [12],
    "proposal": [{      
        "duration": 55,
        "price" : 300,
        "status":"VISIBLE"  
    }],
    "created": "2017-11-30T11:00:36.717Z",
    "modified": "2017-11-30T11:00:36.717Z"
}

How can I do that in Solr?

I have gone through http://yonik.com/solr-nested-objects/ and other documentations and I have below concerns

  1. I didn't get how should we map child document to "proposal" key?
  2. I think, fields such as "ID", "countryIso", "regionId" are defined as required in parent document, so is it necessary to use those fields in child documents also?
Holger Thurow
  • 764
  • 4
  • 12

1 Answers1

1

You have to list child documents under the special key "_childDocuments_". In Apache Solr Reference Guide you will find this example and the hint "note the special _childDocuments_ key need to indicate the nested documents in JSON":

{
    "id": "1",
    "title": "Solr adds block join support",
    "content_type": "parentDocument",
    "_childDocuments_": [{
        "id": "2",
        "comments": "SolrCloud supports it too!"
    }]
}

Note the id field a child document must have too.

Then use Block Join Children Query Parser to find children by parent attributes and Block Join Parent Query Parser to find parents by children attributes. See https://lucene.apache.org/solr/guide/6_6/other-parsers.html#OtherParsers-BlockJoinQueryParsers

Holger Thurow
  • 764
  • 4
  • 12
  • Its also convenient to add at the child a new field such as: "content_type:"childDocument", for filtering purposes. – Joel Mata Feb 05 '19 at 13:32