Elasticsearch在index1和index2中删除/更新文档 [英] Elasticsearch delete/update a document in index1 and index2

查看:140
本文介绍了Elasticsearch在index1和index2中删除/更新文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有两个索引,那么Ex:sample1和sample2。
如果我删除或更新sample1中的值,那么相应的文档也应该在sample2中删除或更新?

If I have two index, Ex: sample1 and sample2. If I delete or update a value in sample1 then the corresponding document should also deleted or updated in sample2?

数据:sample1:{name:'Tom' ,id:'1',city:'xx',state,'yy',country:'zz'}
sample2:{id:'1',city:'xx',state,'yy'国家:'zz'}
如果我删除id:'1',那么这个文件应该从服务器端本身的索引中删除。怎么办?
问题将是如果我删除值separatley然后如果我最后在网络问题,从一个索引中删除值后,另一个索引将有值如何避免这个?

Data : sample1 : {name: 'Tom', id: '1', city: 'xx', state, 'yy', country: 'zz'} sample2 : {id: '1', city: 'xx', state, 'yy', country: 'zz'} If I delete id: '1' then this document should be deleted from both the index from the server side itself. How to do this ? The problem will be if I delete the values separatley then if I end up in network issue after deleting value from one index the other index will have values how to avoid this ?

推荐答案

您可以使用批量API ,您将有更好的保证删除/更新操作成功或失败,因为一切都发生在单个网络呼叫中:

You can use the bulk API for doing this and you'll have better guarantees that both delete/update operations succeed or fail since everything happens in a single network call:

要删除两个不同索引的文档:

For deleting both documents in two different indices:

POST _bulk
{"delete": {"_index": "index1", "_type": "type1", "_id": "1"}}
{"delete": {"_index": "index2", "_type": "type2", "_id": "1"}}

要更新两个不同索引的文档: p>

For updating both documents in two different indices:

POST _bulk
{"index": {"_index": "index1", "_type": "type1", "_id": "1"}}
{"name": "Tom", id: "1", "city": "xx", "state": "yy", "country": "zz"}
{"index": {"_index": "index2", "_type": "type2", "_id": "1"}}
{"id": "1", "city": "xx", "state": "yy", "country": "zz"}

更新

这样,似乎需要的解决方案是使用

After discussing this, it seemed the needed solution was a mix of using

  • the delete-by-query API (don't forget to install the plugin if you're on ES 2.x) for deleting documents matching a country in multiple indices
  • and the update-by-query API for updating documents in multiple indices.

这篇关于Elasticsearch在index1和index2中删除/更新文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆