0

我正在使用 Elasticsearch 5.1.1,在我的索引中批量插入文档,我需要在响应中获取文档字段之一以及自动生成的 _id 来更新数据库。

我一直在尝试以下请求:

curl -XPOST localhost:9200/_bulk?pretty -d '
{ "index" : { "_index" : "articles_201701", "_type" : "articles_type" , "_source_include" : "db_id"} }
{ "db_id" : "value1" }
{ "index" : { "_index" : "articles_201701", "_type" : "articles_type" , "_source_include" : "db_id"} }
{ "db_id" : "value2" }
'


curl -XPOST localhost:9200/_bulk?pretty -d '
{ "index" : { "_index" : "articles_201701", "_type" : "articles_type", "fields" : ["db_id"]} }
{ "db_id" : "value1" }
{ "index" : { "_index" : "articles_201701", "_type" : "articles_type", "fields" : ["db_id"]} }
{ "db_id" : "value2" }
'

curl -XPOST 'localhost:9200/_bulk?pretty&fields=db_id' -d '
{ "index" : { "_index" : "articles_201701", "_type" : "articles_type" } }
{ "db_id" : "value1" }
{ "index" : { "_index" : "articles_201701", "_type" : "articles_type"} }
{ "db_id" : "value2" }
' 

其中一些有轻微的变化和组合,但没有运气。

不确定这是否可能......

4

1 回答 1

0

创建对象数组,每个对象包含 db_Id 和 Id。在调用 bulk 之前设置 db_id ,在调用 bulk 之后使用 elasticsearch 生成的 _id 设置 id 字段。现在,当您要更新时,您有 Id 和 db_id

于 2016-12-30T07:28:29.897 回答