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

ElasticsearchCurlMime TypesContent TypeHttp Put

Elasticsearch Problem Overview


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

Elasticsearch Solutions


Solution 1 - Elasticsearch

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.

Solution 2 - Elasticsearch

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**'

Solution 3 - Elasticsearch

"{ \"name\": { \"first\": {} }, \"address\": [ { \"address1\":\"lane\" } ] } "

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBarry LeishmanView Question on Stackoverflow
Solution 1 - Elasticsearchkgf3JfUtWView Answer on Stackoverflow
Solution 2 - ElasticsearchZ.LIView Answer on Stackoverflow
Solution 3 - Elasticsearchcharlie9526View Answer on Stackoverflow