jsonapachecurlcmdsolr

Sending JSON Data to Solr using cUrl


How do I can send JSON object to solr collection usinc cUrl

I'm using Windows 10.

curl -X POST -H "Content-Type:application/json" "http://localhost:8983/solr/solr_sample/update/json/docs" --data-binary "{'id': '1','title':'Doc 1'}"

When I'm using this format I'm getting some kind of warning message:

curl -X POST -H 'Content-Type:application/json' 'http://localhost:8983/solr/sorl_sample/update/json/docs' --data-binary '{"id": "1","title":"Doc 1"}'
curl: (1) Protocol "'http" not supported or disabled in libcurl
curl: (3) [globbing] unmatched close brace/bracket in column 14

I resolved it using " " insted of ' '

When I send the request using the first url I'm getting this response:

{
  "responseHeader":{
    "status":0,
    "QTime":112}}

But when I try to get some result by searching I can't see any object in docs[]

curl -X GET "http://localhost:8983/solr/solr_sample/select?q=*:*"

Result:

{
      "responseHeader":{
        "status":0,
        "QTime":0,
        "params":{
          "q":"*:*"}},
      "response":{"numFound":0,"start":0,"docs":[]
      }}

When I'm using Solr UI I can add JSON objects without any problems, also to see the result in terminal


Solution

  • You have to commit the update. Add commit=true to the URL path or "commitWithin":1000 to the JSON request, e. g.

    curl -X POST \
        -d '{"add":{"doc":{"id":"delete.me","title":"change.me"},"commitWithin":1000}}' \
        -H "Content-Type: application/json" \
        http://localhost:8983/solr/solr_sample/update
    

    Or using the URL:

    curl -X POST \
        -d '{"add":{ "doc":{"id":"delete.me","title":"change.me"}}}' \
        -H "Content-Type: application/json" \
        http://localhost:8983/solr/solr_sample/update?commit=true