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

Barry Leishman picture Barry Leishman · Nov 29, 2017 · Viewed 78.5k times · Source

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"
        }
      }
    }
  }
}'

Answer

kgf3JfUtW picture kgf3JfUtW · Nov 29, 2017

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.