不支持ElasticSearch - Content-Type标头[application/x-www-form-urlencoded]

Bar*_*man 107 curl content-type http-put mime-types elasticsearch

我以前有ElasticSearch 5.2,刚刚升级到6.0.

我试图在这里按照指南创建一个索引模板,但是得到了错误

Content-Type header [application/x-www-form-urlencoded] is not supported
Run Code Online (Sandbox Code Playgroud)

我的疑问是

curl -X PUT localhost:9200/_template/template_1 -d '
{
  "index_patterns": ["te*", "bar*"],
  "mappings": {
    "type1": {
      "properties": {
        "host_name": {
          "type": "keyword"
        }
      }
    }
  }
}'
Run Code Online (Sandbox Code Playgroud)

sam*_*sam 195

要解决此问题,请添加curl选项 -H 'Content-Type: application/json'


这个错误是由于严格的内容类型检查在ElasticSearch 6.0中引入,在解释这个岗位

从Elasticsearch 6.0开始,包含正文的所有REST请求也必须为该正文提供正确的内容类型.

  • @haneulkim如果在Windows上运行curl,则需要使用双引号字符而不是单引号。以下是 Windows 上的示例 curl 命令:curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" -d" {\"name\": \"John Doe \"}" (8认同)
  • @sam感谢sam,但是当我添加curl选项时,它给我{“error”:“Content-Type header [application/x-www-form-urlencoded] is not support”,“status”:406}curl:(6)无法解析主机:应用程序 (2认同)

Z.L*_*.LI 5

解决方法是添加Content-Type: application/json标题

curl -XPUT 'localhost:9200/_template/template_1' \
  -H 'Content-Type: application/json' \
  -d '**your query**'
Run Code Online (Sandbox Code Playgroud)


小智 5

"{ \"name\": { \"first\": {} }, \"address\": [ { \"address1\":\"lane\" } ] } "
Run Code Online (Sandbox Code Playgroud)

在 Windows 中,当您将 JSON 作为参数提供时,仅使用双引号。使用转义字符。