PUT Index mapping via curl result an error (Content-Type header fix does not working)

Hi everyone !

I migrated from ES 5 to ES 6, and I've tried to push the following mapping with curl as usual:

"mappings" : {
"mee": {
    "properties" : {
        "ind1" : { "type" : "float" },
        "ind2" : { "type" : "float" },
        "ind3" : { "type" : "float" },
        "time" : { "type" : "date", "format" : "HH:mm:ss" },
        "name" : { "type" : "string" },
        "timestamp" : { "type" : "date", "format" : "yyyy-MM-dd HH:mm:ss" },
    }
}

With the following command:

$ curl -XPUT "http://localhost:9200/mee/" -d @config/ESConf/ESUpdate.conf
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}

And as the header is necessary I've made the following:

$ curl -XPUT "http://localhost:9200/mee/" -H 'Content-Type: application/json' -d @config/ESConf/ESUpdate.conf
{"error":{"root_cause":[{"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}],"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"},"status":500}

And now I am completely lost... Just don't understand this error... Did I made something wrong ?

Thank you :slightly_smiling_face:

Hey!

So I installed elastic 6.0.1 as confirmed below

http :9200
HTTP/1.1 200 OK
content-encoding: gzip
content-length: 276
content-type: application/json; charset=UTF-8

{
    "cluster_name": "elasticsearch",
    "cluster_uuid": "IvAbUG-HSYaiJLcmjjwUMg",
    "name": "cGwtenD",
    "tagline": "You Know, for Search",
    "version": {
        "build_date": "2017-12-04T09:29:09.525Z",
        "build_hash": "601be4a",
        "build_snapshot": false,
        "lucene_version": "7.0.1",
        "minimum_index_compatibility_version": "5.0.0",
        "minimum_wire_compatibility_version": "5.6.0",
        "number": "6.0.1"
    }
}

I copied your mapping json, which has a few syntax errors (missing brackets etc). So the fixed version is here

{
  "mappings": {
    "mee": {
      "properties": {
        "ind1": {
          "type": "float"
        },
        "ind2": {
          "type": "float"
        },
        "ind3": {
          "type": "float"
        },
        "time": {
          "type": "date",
          "format": "HH:mm:ss"
        },
        "name": {
          "type": "string"
        },
        "timestamp": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss"
        }
      }
    }
  }
}

However the type for name is incorrect which should either be keyword or text as mentioned here in Core Data Types

So the fixed mapping for name (I just randomly chose text)

"name": {
  "type": "text"
},

With the fixed mapping when I tried

$> curl -XPUT 'localhost:9200/mee' -H 'Content-Type: application/json' -d @mapping.json

I got

{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "mee"
}

Try fixing your JSON errors first and see if that works!

2 Likes

Yep I've missed few things on my mapping...

On ES 5 when I made something wrong, I had a json parse error or a pretty clear error. Here that's the first time I see this kind of error... Maybe this is because of the new header requirement on ES 6.

Thank you anyway :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.