将JSON/XML/TXT/CSV文件发送到ElasticSearch

Zai*_*ani 4 ubuntu json curl http elasticsearch

我一直在尝试将各种格式的数据发送到我的计算机上运行的ElasticSearch.

我正在运行Ubuntu 17(最新版本),但我无法这样做.

以下是我在终端上使用的命令:

curl -X POST 'http://localhost:9200/json/test/2' -d @json.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)

我在网上搜索无济于事.

我究竟做错了什么?

小智 9

你可以这样做:

curl -XPUT 'localhost:9200/twitter/tweet/1?pretty' -H 'Content-Type: application/json' -d'
{
    "user" : "kimchy",
    "post_date" : "2009-11-15T14:12:12",
    "message" : "trying out Elasticsearch"
}
'
Run Code Online (Sandbox Code Playgroud)

您的请求未通过的原因是您没有将Content-Type指定为JSON.另外,你应该使用PUT而不是POST :)我从这个文档复制了这个请求:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html.干杯.

  • 谢谢.所以,我从https://www.elastic.co/blog/strict-content-type-checking-for-elasticsearch-rest-requests得知这个新增加的强制`http.content_type.required`是真实的,从6.0版开始. 0 (2认同)