血と汗となみだを流す

クラウドエンジニアになるための修業の場

Elasticsearch Serviceへcurlでデータを登録しようとしたらエラー

環境

  • AWSのElasticsearch Service
  • バージョン: 6.3

発生したエラー

  • 実行したコマンド
curl -XPUT https://[ES_ENDPOINT]/blog/article/1 -d '
{
    "title": "test title 001",
    "content": "test content 001",
    "tags": ["aws", "infra"]
}
'
  • 発生したエラー
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}%

原因

In earlier releases of Elasticsearch, the content-type was optional, and if it was missing or not recognised, then the server would sniff the content and make an educated guess regarding the content-type. 
That will no longer happen in Elasticsearch 6.0 - every incoming request needs to have the correct content-type for the body it contains.

正しいコマンド

  • Content-Type を指定する
curl -H "Content-Type: application/json" -XPUT https://[ES_ENDPOINT]/blog/article/1 -d '
{
    "title": "test title 001",
    "content": "test content 001",
    "tags": ["aws", "infra"]
}
'
  • 成功した際の戻り値
{"_index":"blog","_type":"article","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}%