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

101,333

Solution 1

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

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

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

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

Share:
101,333

Related videos on Youtube

Barry Leishman
Author by

Barry Leishman

Java Lover

Updated on June 16, 2020

Comments

  • Barry Leishman
    Barry Leishman almost 4 years

    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"
            }
          }
        }
      }
    }'
    
  • Rupesh
    Rupesh about 5 years
    Hi @sam, Is there any permanent solution so that I don't have to give this flag for each request.
  • chaikov
    chaikov over 4 years
    @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
  • Kevin Le
    Kevin Le about 4 years
    @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\"}"
  • Freeze
    Freeze over 3 years
    Thanks, this was really helpful