What is the most optimized/shortest JSON structure I can use to submit multiple records to SOLR
Is this JSON legal to add documents to SOLR?
{
"add": [{"doc": {"id" : "TestDoc1", "ti开发者_高级运维tle" : "test1"} },
{"doc": {"id" : "TestDoc2", "title" : "another test"} },
{"doc": {"id" : "TestDoc1", "title" : "test1"} },
{"doc": {"id" : "TestDoc2", "title" : "another test"}}]
}
I am using SOLR 3.4 and submit using CURL from inside PHP. What should I see in the logs if this is not correct?
EDIT:This question was mistakenly understood as if I have a bug in the structure above (I did have a missing bracket) That was not the purpose. The question is a more generalized one, I edited the title to reflect this.
You are missing a }
at the end there, are you not?
{
"add": [{"doc": {"id" : "TestDoc1", "title" : "test1"} },
{"doc": {"id" : "TestDoc2", "title" : "another test"} },
{"doc": {"id" : "TestDoc1", "title" : "test1"} },
{"doc": {"id" : "TestDoc2", "title" : "another test"} }]
}
According to this site:
http://jsonformatter.curiousconcept.com/
No, it is not valid JSON.
Here it is, cleaned up for you:
{
"add": [
{"doc": {"id" : "TestDoc1", "title" : "test1"} },
{"doc": {"id" : "TestDoc2", "title" : "another test"} },
{"doc": {"id" : "TestDoc1", "title" : "test1"} },
{"doc": {"id" : "TestDoc2", "title" : "another test"} }
]
}
Use -
curl http://localhost:8983/solr/update/json -H 'Content-type:application/json' -d '
{
"add": {"doc": {"id" : "TestDoc1", "title" : "test1"} },
"add": {"doc": {"id" : "TestDoc2", "title" : "another test"} },
"add": {"doc": {"id" : "TestDoc1", "title" : "test1"} },
"add": {"doc": {"id" : "TestDoc2", "title" : "another test"}}
}'
OR
curl http://localhost:8983/solr/update/json -H 'Content-type:application/json' -d '
[
{"id" : "TestDoc1", "title" : "test1"},
{"id" : "TestDoc2", "title" : "another test"},
{"id" : "TestDoc1", "title" : "test1"},
{"id" : "TestDoc2", "title" : "another test"}
]'
精彩评论