将数据上传到弹性搜索时出错

时间:2015-07-19 09:46:26

标签: curl elasticsearch

问题:

当我使用下面的curl命令将数据发送到弹性搜索时,我得到以下错误

命令: 我使用curl命令创建了以下模板,它工作正常

  

curl -X PUT http://localhost:9200/_template/cn_health_monitoring -d' {"模板":" cn_health_monitoring","设置":{&#34 ; index.refresh_interval":" 5S"}"映射" {" 默认" {" _all" {"启用":真}"属性" {" @时间戳" {"类型":&# 34;串"}" appliance_id_string" {"类型":"串""指数":" not_analyzed& #34;}" mother_board_serial_number" {"类型":"串""指数":" not_analyzed" }," mother_board_name" {"类型":"串""指数":" 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笔记本电脑"}'

错误:

{
    "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]"
            }
        }
    ]
}

1 个答案:

答案 0 :(得分:0)

首先,您在mother_board_serial_number

之前缺少逗号

然后,您可以使用文件执行此操作(可能还有其他方法,但这似乎有效)

eran@eran-laptop:~$ 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"}

eran@eran-laptop:~$ 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}}]}