4

I uesd following command from elasticsearch tutorial,

curl -XPUT "http://localhost:9200/movies/movie/1" -d" { "title": "The Godfather","director": "Francis Ford Coppola","year": 1972}"

Which produces following error:

{
    "error":"MapperParsingException[failed to parse]; nested: JsonParseException[Unrecognized token 'The': was expecting ('true', 'false' or 'null')
             at [Source: [B@d809e3; line: 1, column: 27]]; ",
    "status":400
}

curl: (6) Could not resolve host: Godfather,director
curl: (6) Could not resolve host: Ford
curl: (3) [globbing] unmatched close brace/bracket in column 19

Could anyone please help, what i need to do to rectify this error?

peter
  • 14,348
  • 9
  • 62
  • 96
Pankaj Kumar
  • 255
  • 5
  • 17

3 Answers3

11

The problem is that you use the same quote sign for properties and values inside the JSON object as well as the document itself which you are passing to curl.

Run this command instead:

curl -XPUT "http://localhost:9200/movies/movie/1" -d '{
  "title": "The Godfather",
  "director": "Francis Ford Coppola",
  "year": 1972
}'

Update:

since you are running the command on windows, the above solution won't work, instead your answer can be answered here:

This resulting command should work:

curl -X PUT "http://localhost:9200/movies/movie/1" -d "{ 
  ""title"": ""The Godfather"",
  ""director"": ""Francis Ford Coppola"",
  ""year"": 1972
}"
Community
  • 1
  • 1
peter
  • 14,348
  • 9
  • 62
  • 96
  • Getting Error: {"error":"MapperParsingException[failed to parse]; nested: JsonParseException[Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: [B@18fcb66; line: 1, column: 2]]; ","status":400}curl: (6) Could not resolve host: title curl: (6) Could not resolve host: The Godfather,director – Pankaj Kumar Mar 20 '14 at 12:17
  • if you run it in windows, you should mention it in your question. the provided command works fine in linux (ubuntu) – peter Mar 20 '14 at 12:28
  • Yes, actually i run it in Windows 7. What changes do i need? Any suggestion – Pankaj Kumar Mar 20 '14 at 12:35
2

I think you are struggling more in curl commands.

Try to use sense plug in in Chrome or Crest client extension for chrome..

https://chrome.google.com/webstore/detail/dev-http-client/aejoelaoggembcahagimdiliamlcdmfm?hl=en

https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo?hl=en

It is very easy to use and easy understandable..

BlackPOP
  • 5,657
  • 2
  • 33
  • 49
0

Instead of using -d, try to use --data-binary. Create a movie.json file and add json below into the file

{
  "title": "The Godfather",
  "director": "Francis Ford Coppola",
  "year": 1972
}

and try to run following command

curl -XPUT "http://localhost:9200/movies/movie/1" --data-binary @movie.json
Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
tsong
  • 23
  • 3