Adding Documents via REST API in ElasticSearch

I am getting this error while trying to run this code to add data/document In Elasticsearch version 6.4.1 in windows

curl -X POST "localhost:9200/clusters/_doc" -H "Content-Type" : application/json -d "{ "field1":"value1", "field2": "value2", "field3" : "value3"}"

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"json_parse_exception","reason": "Unexpected character ('f' (code 102)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@f397fba; line: 1, column: 4]"}},"status":400}

Version 6.4.1 is very, very old and has been EOL for years. I would recommend you upgrade to the latest version.

It looks like your request is malformed. Try this instead: curl -X POST "localhost:9200/clusters/_doc" -H "Content-Type: application/json" -d '{ "field1":"value1", "field2": "value2", "field3" : "value3"}'

I tried starting the v8.9.1 but started giving me errors, so that's why I chose this version.

I tried running your code and it again gave me this:
curl -X POST "localhost:9200/clusters/_doc" -H "Content-Type: application/json" -d '{"field1":"value1", "field2": "value2", "field3" : "value3"}'

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}},"status":400}
curl: (6) Could not resolve host: field2
curl: (6) Could not resolve host: value2,
curl: (6) Could not resolve host: field3
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched close brace/bracket in URL position 7:
value3}'

I just noticed that you are using Windows. Curl on Windows is not the same as standard curl, so it may be a Windows specific issue. I would recommend trying to create the document in the Kibana dev tools console. You may also try some other tool, e.g. Postman, to send the request.

I see, thank you @Christian_Dahlqvist

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.