Elasticsearch Bulk API : 不能 post 多条记录

Elasticsearch Bulk API : Cannot post more than one record

我正在尝试 post 使用批量 api 以下内容。我有 ES 2.2.0

{"index":{"_index":"junktest","_type":"test"}}
{"DocumentID":"555662","Tags":["B","C","D"],"Summary":"Summary Text","Status":"Review","Location":"HDFS","Error":"None","Author":"Abc Mnb","Sector":"Energy","Created Date":"2013-05-23"},
{"DocumentID":"555663","Tags":["A","B","C"],"Summary":"Summary Text","Status":"Review","Location":"HDFS","Error":"None","Author":"Abc Mnb","Sector":"Energy","Created Date":"2013-04-25"}

作为

curl -XPOST "http://localhost:9200/_bulk" --data-binary @post.json

但我明白了

  {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Malformed
     action/metadata line [3], expected START_OBJECT or END_OBJECT but found [VALUE_
STRING]"}],"type":"illegal_argument_exception","reason":"Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found [VALUE_STRING]"},"status":400}

为什么},无效?我什至在没有逗号的情况下尝试过,但我仍然收到错误,即使我没有 , !

我的语法有什么问题?

编辑

我能够通过

让它工作
{"index":{"_index":"junktest","_type":"test"}}
{"DocumentID":"555662","Tags":["B","C","D"],"Summary":"Summary Text","Status":"Review","Location":"HDFS","Error":"None","Author":"Abc Mnb","Sector":"Energy","Created Date":"2013-05-23"}
{"index":{"_index":"junktest","_type":"test"}}
{"DocumentID":"555663","Tags":["A","B","C"],"Summary":"Summary Text","Status":"Review","Location":"HDFS","Error":"None","Author":"Abc Mnb","Sector":"Energy","Created Date":"2013-04-25"}

这是使用批量 api 索引多个记录的唯一方法吗?

来自文档

The REST API endpoint is /_bulk, and it expects the following JSON structure:

action_and_meta_data\n
optional_source\n
action_and_meta_data\n
optional_source\n
....
action_and_meta_data\n
optional_source\n

document source 是可选的,但 action_meta_data 是必需的,两者之间用换行符分隔。 鉴于这些限制,您只能为每个操作指定一条记录。

另外,在您提供的示例中,您没有在元数据中传递“_id”,这意味着“_id”是自动生成的。可能是有意为之,但请记住,如果您打算更新文档,您将无法使用 DocumentId.

JSON 结构中应该没有换行符,以前我用这个输入做的,它产生了上面的错误,

{ 
"index" : { "_index" : "ecommerce", "_type" : "product", "_id" : "1002" 
} 
}
{ "id": 2}

现在它可以正常使用以下输入

{ "index" : { "_index" : "ecommerce", "_type" : "product", "_id" : "1002" } }
{ "id": 2}
{"index":{ "_index" : "ecommerce", "_type" : "product","_id":"1003"}}
{ "id": 3,"name":"Dot net"}

最后一条记录后的换行符对于让它正常工作很重要。我通过在最后一条记录的末尾添加 \n(换行符)解决了类似的问题。

例如这行不通:

"{ "name":"Central School", "description":"CBSE Affiliation", "street":"Nagan"}"

但这会

"{ "name":"Central School", "description":"CBSE Affiliation", "street":"Nagan"} \n “