You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2010/12/07 17:12:01 UTC

[Solr Wiki] Update of "UpdateJSON" by YonikSeeley

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.

The "UpdateJSON" page has been changed by YonikSeeley.
The comment on this change is: start doc for JSON updates.
http://wiki.apache.org/solr/UpdateJSON

--------------------------------------------------

New page:
= Updating a Solr Index with JSON =

Solr accepts index updates in [[http://en.wikipedia.org/wiki/JSON|JSON]] format.

<!> [[Solr3.1]]

<<TableOfContents>>

== Requirements ==
<!> [[Solr3.1]] is the first version with JSON support for updates.

The JSON request handler needs to be configured in solrconfig.xml
This should already be present in the example solrconfig.xml
{{{
  <requestHandler name="/update/json" class="solr.JsonUpdateRequestHandler"/>
}}}

== Methods of sending JSON ==
JSON formatted update requests may be sent to Solr via the /solr/update/json URL.
All of the normal methods for [[ContentStream|uploading content]] are supported.

=== Example ===
There is a sample JSON file at {{{example/exampledocs/books.json}}} that may be used to add documents to the solr example server.

Example of using HTTP-POST to index the JSON:
{{{
cd example/exampledocs
curl 'http://localhost:8983/solr/update/json?commit=true' --data-binary @books.json -H 'Content-type:application/json'
}}}

Note that we added "commit=true" to the URL so that the documents would be immediately searchable.

You should now be able to query for the newly added documents:
http://localhost:8983/solr/select?q=title:monsters&wt=json&indent=true
{{{
{
  "responseHeader":{
    "status":0,
    "QTime":2,
    "params":{
      "indent":"true",
      "wt":"json",
      "q":"title:monsters"}},
  "response":{"numFound":1,"start":0,"docs":[
      {
        "id":"978-1423103349",
        "author":"Rick Riordan",
        "series_t":"Percy Jackson and the Olympians",
        "sequence_i":2,
        "genre_s":"fantasy",
        "inStock":true,
        "price":6.49,
        "pages_i":304,
        "title":[
          "The Sea of Monsters"],
        "cat":["book","paperback"]}]
  }}
}}}

It's also easy to specify JSON documents from the command line for testing purposes and scripts (assumes a UNIX environment):
{{{
URL=http://localhost:8983/solr/update/json
curl $URL -H 'Content-type:application/json' -d '
{
 "add": {
  "doc": {
    "id" : "MyTestDocument",
    "title" : "This is just a test"
  }
 }
}'
curl "$URL?commit=true"
}}}