【elasticsearch7】{“error“:“Content-Type header [application/x-www-form-urlencoded] is not supported“

报错内容

执行内容:

curl -X PUT "172.31.254.22:9200/test" -d '
{
    "mappings": {
            "properties": {
                "name": {
                    "type": "text"
                },
                "age": {
                    "type": "long"
                }
            }
    }
}'

报错内容:

{
	"error": "Content-Type header [application/x-www-form-urlencoded] is not supported",
	"status": 406
}

解决方法

需要添加HTTP

-H "Content-Type: application/json"

最终修改如下:

curl -H "Content-Type: application/json" -X PUT "172.31.254.22:9200/test" -d '
{
    "mappings": {
            "properties": {
                "name": {
                    "type": "text"
                },
                "age": {
                    "type": "long"
                }
            }
    }
}'

参考:https://www.elastic.co/cn/blog/strict-content-type-checking-for-elasticsearch-rest-requests

posted @ 2022-11-10 19:25  彬在俊  阅读(35)  评论(0编辑  收藏  举报