環境
- 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.
正しいコマンド
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}%