183

I used to have ElasticSearch 5.2, and just upgraded to 6.0.

I am trying to create an index template following guide here, but got error

Content-Type header [application/x-www-form-urlencoded] is not supported

My query is

curl -X PUT localhost:9200/_template/template_1 -d '
{
  "index_patterns": ["te*", "bar*"],
  "mappings": {
    "type1": {
      "properties": {
        "host_name": {
          "type": "keyword"
        }
      }
    }
  }
}'

3 Answers 3

310

To fix this, add curl option -H 'Content-Type: application/json'


This error is due to strict content-type checking introduced in ElasticSearch 6.0, as explained in this post

Starting from Elasticsearch 6.0, all REST requests that include a body must also provide the correct content-type for that body.

3
  • Hi @sam, Is there any permanent solution so that I don't have to give this flag for each request.
    – Rupesh
    May 8, 2019 at 13:34
  • 4
    @sam thanks sam however when I add curl option it give me {"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}curl: (6) Could not resolve host: application
    – chaikov
    Oct 23, 2019 at 1:18
  • 12
    @haneulkim If running curl on Windows, you need to use double quote character instead of single quote. Here is example curl command on Windows: curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" -d" {\"name\": \"John Doe\"}"
    – Kevin Le
    Mar 16, 2020 at 3:34
19

The solution is to add Content-Type: application/json header

curl -XPUT 'localhost:9200/_template/template_1' \
  -H 'Content-Type: application/json' \
  -d '**your query**'
0
5
"{ \"name\": { \"first\": {} }, \"address\": [ { \"address1\":\"lane\" } ] } "

In Windows, when you give JSON as a parameter, use double quotes only. Use escape character.

1
  • Thanks, this was really helpful
    – Freeze
    Sep 24, 2020 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.