【问题标题】:Content-Type header [application/x-www-form-urlencoded] is not supported on ElasticsearchElasticsearch 不支持 Content-Type 标头 [application/x-www-form-urlencoded]
【发布时间】:2018-05-12 16:48:54
【问题描述】:

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

我正在尝试按照指南 here 创建索引模板,但出现错误

Content-Type header [application/x-www-form-urlencoded] is not supported

我的查询是

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

【问题讨论】:

    标签: elasticsearch curl mime-types content-type http-put


    【解决方案1】:

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


    此错误是由于 ElasticSearch 6.0 中引入了严格的内容类型检查,如this post中所述

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

    【讨论】:

    • 嗨@sam,有没有永久的解决方案,这样我就不必为每个请求提供这个标志。
    • @sam 谢谢 sam 但是当我添加 curl 选项时它给了我 {"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status" :406}curl: (6) 无法解析主机:应用程序
    • @haneulkim 如果在 Windows 上运行 curl,您需要使用双引号字符而不是单引号。这是 Windows 上的 curl 命令示例: curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" -d" {\"name\": \"John Doe \"}"
    【解决方案2】:

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

    curl -XPUT 'localhost:9200/_template/template_1' \
      -H 'Content-Type: application/json' \
      -d '**your query**'
    

    【讨论】:

      【解决方案3】:
      "{ \"name\": { \"first\": {} }, \"address\": [ { \"address1\":\"lane\" } ] } "
      

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

      【讨论】:

      • 谢谢,这真的很有帮助
      猜你喜欢
      • 2019-05-24
      • 2018-12-27
      • 2018-06-20
      • 2019-02-04
      • 1970-01-01
      • 1970-01-01
      • 2013-11-10
      • 1970-01-01
      • 2019-10-26
      相关资源
      最近更新 更多