elasticsearch Elasticsearch 5-批量插入时文档返回字段,elasticsearch,elasticsearch-5,elasticsearch,elasticsearch 5" /> elasticsearch Elasticsearch 5-批量插入时文档返回字段,elasticsearch,elasticsearch-5,elasticsearch,elasticsearch 5" />

elasticsearch Elasticsearch 5-批量插入时文档返回字段

elasticsearch Elasticsearch 5-批量插入时文档返回字段,elasticsearch,elasticsearch-5,elasticsearch,elasticsearch 5,我正在使用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

我正在使用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" }
' 
其中一些有轻微的变化和组合,但没有运气


不确定这是否可能…

创建对象数组,每个对象都包含db\u Id和Id。在调用bulk之前设置db\u Id,在调用bulk之后使用elasticsearch生成的_Id设置Id字段。现在,当你想更新你的Id和db_Id时,当使用批量插入文档时,你需要应用_索引、_类型和_Id,如果你不应用_Id,elasticsearch将为你生成_Id,并且在响应中你将得到生成_Id。elasticsearch不会生成其他字段感谢你的回答,对不起,也许我没有解释清楚,我确实需要ES来生成_id,但我也需要它返回“db_id”字段(是的,我从文档中索引的字段)以及_id。这样我可以执行类似于
updatetable set elastic_id=:_id其中db_id=:db_id
的操作,但是,我认为查询返回的_id可能不是正确的方法(从大容量插入)要知道db_ID的开销太大……我想做的是类似pgsql的
插入表值(?,,?)返回id,name
如果生成db_id,为什么需要elasticsearch为您返回?因为我需要使用elasticsearch_id更新数据库,我只在索引文档后才知道这一点,但由于这是批量插入,我得到一个长列表,其中包含各个索引操作的结果(使用_id)并且不知道哪个db_id与哪个_id配对创建对象数组,每个对象都包含db_id和id。在调用bulk之前设置db_id,在调用bulk之后使用elasticsearch生成的_id设置id字段。现在,当您要更新时,您有id和db_id