2015-07-19 50 views
0

問題:得到錯誤,同時將數據上傳到彈性搜索

當我使用下面的curl命令到彈性搜索即時得到下面的錯誤

命令發送數據: 我使用創建下面的模板curl命令它工作得很好

curl -X PUT http://localhost:9200/_template/cn_health_monitoring -d '{"template":"cn_health_monitoring","settings":{"index.refresh_interval":"5s"},"mappings":{"default":{"_all":{"enabled":true},"properties":{"@timestamp":{"type":"string"},"appliance_id_string":{"type":"string","index":"not_analyzed"},"mother_board_serial_number":{"type":"string","index":"not_analyzed"},"mother_board_name":{"type":"string","index":"not_analyzed"}}}}}'

當我使用下面的命令,我得到的錯誤發送數據500或400

curl -XPOST http://localhost:9200/_bulk -d '{"index":{"_index":"cn_health_monitoring","_type":"ipfix"}} \n {"@timestamp":"2015-07-18 21:39:10","appliance_id_string":" 32444335-3732-4A31-5143-A0B3CC82A9B1""mother_board_serial_number":" 5CD2271JQC","mother_board_name":" HP Pavilion g6 Notebook PC"}'

錯誤:

{ 
    "error": "ActionRequestValidationException[Validation Failed: 1: no requests added;]", 
    "status": 500 
} 

{ 
    "took": 219, 
    "errors": true, 
    "items": [ 
     { 
      "create": { 
       "_index": "cn_health_monitoring", 
       "_type": "ipfix", 
       "_id": "ghfPSLv1Tayw03jTr0Zi6Q", 
       "status": 400, 
       "error": "MapperParsingException[failed to parse, document is empty]" 
      } 
     } 
    ] 
} 

回答

0

首先,你必須在mother_board_serial_number之前缺少逗號

然後,你可以使用文件來做到這一點(也許有其他的方式,但這似乎工作)

[email protected]:~$ cat r 
{"index":{"_index":"cn_health_monitoring","_type":"ipfix"}} 
{"@timestamp":"2015-07-18 21:39:10","appliance_id_string":" 32444335-3732-4A31-5143-A0B3CC82A9B1","mother_board_serial_number":" 5CD2271JQC","mother_board_name":" HP Pavilion g6 Notebook PC"} 

[email protected]:~$ curl -XPOST localhost:9200/_bulk --data-binary @r 
{"took":2,"errors":false,"items":[{"create":{"_index":"cn_health_monitoring","_type":"ipfix","_id":"AU6lweKRmOtv0CHjm9cD","_version":1,"status":201}}]} 
+0

我刪除了逗號,遺憾沒有在這個問題更新它,但它仍然給了我一個錯誤 –

+1

你嘗試與文件?您需要根據https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html使用--data-binary – eran