因此,我们在 Django 项目中使用了 elasticsearch,并且使用了 elasticsearch-dsl python 库。
我们在生产中遇到以下错误:
ConflictError(409, '{"took":7,"timed_out":false,"total":1,"deleted":0,"batches":1,"version_conflicts":1,"noops":0,"retries":{"bulk":0,"search":0},"throttled_millis":0,"requests_per_second":-1.0,"throttled_until_millis":0,"failures":[{"index":"events","type":"_doc","id":"KJ7SpWsBZnen1jNBRWWM","cause":{"type":"version_conflict_engine_exception","reason":"[KJ7SpWsBZnen1jNBRWWM]: version conflict, required seqNo [1418], primary term [1]. current document has seqNo [1419] and primary term [1]","index_uuid":"2-fSZILVQzuJE8KVmpLFXQ","shard":"0","index":"events"},"status":409}]}')
并具有更好的格式:
{
"took": 7,
"timed_out": false,
"total": 1,
"deleted": 0,
"batches": 1,
"version_conflicts": 1,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1.0,
"throttled_until_millis": 0,
"failures": [
{
"index": "events",
"type": "_doc",
"id": "KJ7SpWsBZnen1jNBRWWM",
"cause": {
"type": "version_conflict_engine_exception",
"reason": "[KJ7SpWsBZnen1jNBRWWM]: version conflict, required seqNo [1418], primary term [1]. current document has seqNo [1419] and primary term [1]",
"index_uuid": "2-fSZILVQzuJE8KVmpLFXQ",
"shard": "0",
"index": "events"
},
"status": 409
}
]
}
产生错误的代码是对 dsl
delete
的调用方法:connections.create_connection(
hosts=[settings.ELASTICSEARCH_HOST],
timeout=20,
)
search = EventDocument.search()
# The query is made by the django model's id
search.query('match', id=self.id).delete()
这是
EventDocument
的定义:from elasticsearch_dsl import (
Document,
Integer,
)
class EventDocument(Document):
id = Integer()
# other fields
我们现在最大的问题是我们无权访问服务器,我们通过为错误配置的自动电子邮件收到错误。所以我什至不知道如何重现它。
希望能帮到你,谢谢。
最佳答案
由于文档中的版本冲突,发生此错误。来自 ES 官方文档
Elasticsearch is distributed. When documents are created, updated, or deleted, the new version of the document has to be replicated to other nodes in the cluster. Elasticsearch is also asynchronous and concurrent, meaning that these replication requests are sent in parallel, and may arrive at their destination out of sequence. Elasticsearch needs a way of ensuring that an older version of a document never overwrites a newer version.
阅读有关如何处理
version conflict http 409
的更多信息ES 中的异常 this官方文档,它还解释了为什么会出现异常以及如何处理它的各种方法,并详细解释了这个概念。
关于python - 使用elasticsearch-dsl的delete方法时版本冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56840637/