繁体   English   中英

elasticsearch批量插入JSON文件

[英]elasticsearch bulk insert JSON file

我有以下JSON 文件

我用 awk 去掉了空格、尾随、下一行

awk -v ORS= -v OFS= '{$1=$1}1' data.json

我在 data.json 的顶部添加了一个创建请求,然后是 \\n 和我的其余数据。

{"create": {"_index":"socteam", "_type":"products"}} 

当我发出批量提交请求时,出现以下错误

CURL -XPUT http://localhost:9200/_bulk

{
  "took": 1,
  "errors": true,
  "items": [
    {
      "create": {
        "_index": "socteam",
        "_type": "products",
        "_id": "AVQuGPff-1Y7OIPIJaLX",
        "status": 400,
        "error": {
          "type": "mapper_parsing_exception",
          "reason": "failed to parse",
          "caused_by": {
            "type": "not_x_content_exception",
            "reason": "Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"
          }
        }
      }
    }
  ]

知道这个错误是什么意思吗? 我还没有创建任何映射,我使用的是 vanilla elasticsearch

根据文档,您必须指定索引并输入 URL:

curl -XPUT 'localhost:9200/socteam/products/_bulk?pretty' --data-binary "@data.json"

它适用于 PUT 和 POST 方法。
您的 data.json 文件应具有如下结构:

{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }

也许存在另一种导入数据的方法,但我只知道这一点......希望它会有所帮助......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM