elasticsearch 批量插入 JSON 文件

elasticsearch bulk insert JSON file

我有以下 JSON file

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

awk -v ORS= -v OFS= '{=}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

根据 this 文档,您必须指定索引并输入 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" }

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