Reputation: 2134
I am following the tutorial: https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-index.html
When I copy the command to insert a document, and then I paste it into windows cmd, we see the following:
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
"error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
"status" : 406
}
curl: (6) Could not resolve host: application
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>{
"{" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin> "name": "John Doe"
""name":" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>}
"}" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>'
"'" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
So then I edited the command to fit it into one line as:
curl -XPUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d '{"name":"John Doe"}'
And when we execute it, the cmd outputs:
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>curl -XPUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d '{"name":"John Doe"}'
{
"error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
"status" : 406
}
curl: (6) Could not resolve host: application
I read:
Content-Type header [application/x-www-form-urlencoded] is not supported on Elasticsearch
And I checked that I have already written: -H 'Content-Type: application/json'
Besides I read:
Content-Type header [application/x-www-form-urlencoded] is not supported
And I tried to put double quotes around localhost and content-type:
curl -XPUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" -d '{"name":"John Doe"}'
After executing it we observe:
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>curl -XPUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" -d '{"name":"John Doe"}'
{
"error" : {
"root_cause" : [
{
"type" : "not_x_content_exception",
"reason" : "not_x_content_exception: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"
}
],
"type" : "mapper_parsing_exception",
"reason" : "failed to parse",
"caused_by" : {
"type" : "not_x_content_exception",
"reason" : "not_x_content_exception: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"
}
},
"status" : 400
}
In addition I have tried to replace both quotes with single quotes, and then here we have our cmd trace:
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>curl -XPUT 'localhost:9200/customer/_doc/1?pretty' -H 'Content-Type: application/json' -d '{"name":"John Doe"}'
curl: (6) Could not resolve host: 'localhost
curl: (6) Could not resolve host: application
Plus to check we do have Elastic Search up and running:
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>curl -X GET "localhost:9200/_cat/health?v&pretty"
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1580922144 17:02:24 elasticsearch green 2 2 2 1 0 0 0 0 - 100.0%
How could we solve this?‽‽?
Upvotes: 0
Views: 2416
Reputation: 3667
hah, windows and curl can be cumbersome...
in windows, this version work:
curl -XPUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" -d "{""name"":""John Doe""}"
Please note the double quotes inside the json.
If you're working under windows, try the Windows Linux Subsystem (WSL) or Cygwin. This will help you a lot. Another option is to install kibana and use the dev tools
Upvotes: 1