gpt4 book ai didi

Elasticsearch 按查询版本冲突删除

转载 作者:行者123 更新时间:2023-12-05 06:26:24 26 4
gpt4 key购买 nike

我使用的是 Elasticsearch 5.6.10 版。我有一个删除给定机构记录的查询,因此以后可以通过夜间脚本更新它们。

查询在 elasticsearch-dsl 中,如下所示:

def remove_employees_from_search(jurisdiction_slug, year):
s = EmployeeDocument.search()
s = s.filter('term', year=year)
s = s.query('nested', path='jurisdiction', query=Q("term", **{'jurisdiction.slug': jurisdiction_slug}))
response = s.delete()
return response

问题是我在尝试通过该函数删除记录时遇到了 ConflictError 异常。我已经读到发生这种情况是因为文件在删除过程开始和执行之间是不同的。但我不知道这是怎么回事,因为在删除过程中没有其他东西在修改记录。

我将添加 s = s.params(conflicts='proceed') 以消除异常。但这是一个创可贴,因为我不明白为什么删除没有按预期处理。关于如何解决这个问题的任何想法?错误的快照如下:

ConflictError:TransportError(409,
u'{
"took":10,
"timed_out":false,
"total":55,
"deleted":0,
"batches":1,
"version_conflicts":55,
"noops":0,
"retries":{
"bulk":0,
"search":0
},
"throttled_millis":0,
"requests_per_second":-1.0,
"throttled_until_millis":0,
"failures":[
{
"index":"employees",
"type":"employee_document",
"id":"24681043",
"cause":{
"type":"version_conflict_engine_exception",
"reason":"[employee_document][24681043]: version conflict, current version [5] is different than the one provided [4]",
"index_uuid":"G1QPF-wcRUOCLhubdSpqYQ",
"shard":"0",
"index":"employees"
},
"status":409
},
{
"index":"employees",
"type":"employee_document",
"id":"24681063",
"cause":{
"type":"version_conflict_engine_exception",
"reason":"[employee_document][24681063]: version conflict, current version [5] is different than the one provided [4]",
"index_uuid":"G1QPF-wcRUOCLhubdSpqYQ",
"shard":"0",
"index":"employees"
},
"status":409
}

最佳答案

你可以试试让它先刷新

client.indices.refresh(index='your-index')

来源https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#_indices_refresh

关于Elasticsearch 按查询版本冲突删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56137392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com