Solr's JSON request format isn't valid JSON
-------------------------------------------
Key: SOLR-2627
URL: https://issues.apache.org/jira/browse/SOLR-2627
Project: Solr
Issue Type: Bug
Components: update
Affects Versions: 3.2
Reporter: Brian Pontarelli
Priority: Critical
I've been working with Solr's JSON request and response to get it up and
running in my application and it looks like the JSON request format is not
properly formatted JSON. Here's an example of a request with multiple documents
(from the Wiki):
{
"add": {"doc": {"id" : "TestDoc1", "title" : "test1"} },
"add": {"doc": {"id" : "TestDoc2", "title" : "another test"} }
}
Unfortunately, this is not valid JSON because according to RFC-4627 section
2.2, "The names within an object SHOULD be unique." This means that defining
the name "add" twice is not allowed. Instead, the JSON should use an array for
multiple documents like this:
{
"add": [{"doc": {"id" : "TestDoc1", "title" : "test1"}},
{"doc": {"id" : "TestDoc2", "title" : "another test"}}]
}
An alternate form that simplifies this entire thing is to remove the "doc"
identifier as it doesn't appear to provide useful information. That form would
be:
{
"add": [{"id" : "TestDoc1", "title" : "test1"},
{"id" : "TestDoc2", "title" : "another test"}]
}
It looks like Noggit uses a stream based Parser that doesn't put these values
into a Map or JavaBean, otherwise this would have revealed itself much sooner.
I run into the issue when attempting to create a Map that I could pass to a
JSON binder such as Jackson or Google-GSON. Given the current format, none of
those tools will work with Solr.
It also looks like Noggit is not really moving out of labs. It would be nice to
use a more well known and active project for the JSON handling as it is quickly
becoming the de-facto standard. I can open a ticket for that separately if
needed and help out with the code.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]