不支持内容类型标题

nas*_*nas 3 curl libcurl elasticsearch

我正在跟踪此链接进行Elasticsearch。

https://www.elastic.co/blog/a-practical-introduction-to-elasticsearch
Run Code Online (Sandbox Code Playgroud)

我正在尝试跟随curl发布json数据。

curl -XPOST "http://localhost:9200/shakespeare/_bulk?pretty" --data-binary @D:\data\shakespeare.json
Run Code Online (Sandbox Code Playgroud)

但是我收到如下错误:

{
  "error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
  "status" : 406
}
Run Code Online (Sandbox Code Playgroud)

小智 6

从旧版本更新到 6.xx 后,我收到了同样的错误,我没有直接使用curl语句,而是使用python的elasticsearch插件。

就我而言,我需要安装与更新的 Elasticsearch 服务器相对应的较新版本的插件。

pip 安装elasticsearch==6.3.1

确保在代码执行所在的同一 Python 环境中运行它。

希望这能让某人免于一些头痛。


Phi*_*röm 5

您需要将标题中的内容类型设置为application / json:

curl -XPOST -H "Content-Type: application/json" "http://localhost:9200/shakespeare/_bulk?pretty" --data-binary @D:\data\shakespeare.json
Run Code Online (Sandbox Code Playgroud)