【问题标题】:elasticsearch bulk insert JSON fileelasticsearch批量插入JSON文件
【发布时间】:2016-08-11 12:09:35
【问题描述】:

我有以下JSON file

我已经使用 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

【问题讨论】:

  • 我只有一个 JSON 文件,这意味着我必须分解它吗?
  • _bulk 调用需要使用 POST。你能显示你正在使用的完整 curl 命令吗?您没有显示您的 -d--data-binary 参数。

标签: json search elasticsearch bulkinsert


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 2022-08-10
    • 1970-01-01
    • 2017-11-03
    相关资源
    最近更新 更多