Sunday, April 1, 2018

FW: Indexing multi level Nested JSON using curl

-----Original Message-----
From: Zheng Lin Edwin Yeo [mailto:edwinyeozl@gmail.com]
Sent: 26 March 2018 15:00
To: solr-user@lucene.apache.org
Subject: Indexing multi level Nested JSON using curl

Hi,

I'm trying to index the following JSON with 2 child level using the
following curl command using cygwin:

curl 'http://localhost:8983/solr/collection1/update/json/docs?split=/|/orgs'
-H 'Content-type:application/json' -d '
{
"id":"1",
"name_s": "JoeSmith",
"phone_s": 876876687,
"orgs": [
{
"name1_s" : "Microsoft",
"city_s" : "Seattle",
"zip_s" : 98052,
"orgs":[{"name2_ss":"alan","phone2_ss":"123"},{"name2_ss":
"edwin","phone2_ss":"456"}]
},
{
"name1_s" : "Apple",
"city_s" : "Cupertino",
"zip_s" : 95014,
"orgs":[{"name2_ss":"alan","phone2_ss":"123"},{"name2_ss":
"edwin","phone2_ss":"456"}]
}
]
}'

However, after indexing, this is what is shown in Solr. The 2nd child have
been place together under the 1st child as a multi-valued field, which is
wrong. If I have set the field for the 2nd child to be non-multi-valued
field, it will have error saying "multiple values encountered for non
multiValued field orgs2.name2_s:".

{
"responseHeader":{
"zkConnected":true,
"status":0,
"QTime":41,
"params":{
"q":"phone_s:876876687",
"fl":"*,[child parentFilter=phone_s:876876687]",
"sort":"id asc"}},
"response":{"numFound":1,"start":0,"docs":[
{
"id":"1",
"name_s":"JoeSmith",
"phone_s":"876876687",
"language_s":"en",
"_version_":1595632041779527680,
"_childDocuments_":[
{
"name1_s":"Microsoft",
"city_s":"Seattle",
"zip_s":"98052",
"orgs.name2_ss":["alan",
"edwin"],
"orgs.phone2_ss":["123",
"456"],
"_version_":1595632041779527680},
{
"name1_s":"Apple",
"city_s":"Cupertino",
"zip_s":"95014",
"orgs.name2_ss":["alan",
"edwin"],
"orgs.phone2_ss":["123",
"456"],
"_version_":1595632041779527680}]}]
}}


How can we structure the curl command so it will be able to accept child of
child relationship? We should not be doing any pre-processing to the JSON to
achieve that.

I'm using Solr 7.2.1.

Regards,
Edwin

No comments:

Post a Comment