簡體   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