So, we're using elasticsearch in our Django project, and we're using the elasticsearch-dsl python library.
We got the following error in production:
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}]}')
And with better formatting:
{
"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
}
]
}
The code that produced the error was this call to the dsl delete
method:
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()
And here's the definition of EventDocument
:
from elasticsearch_dsl import (
Document,
Integer,
)
class EventDocument(Document):
id = Integer()
# other fields
Our biggest issue right now is that we don't have access to the server, we got the error through an automated email we configured for errors. So I don't even know how to reproduce it.
Hope you can help, thanks.
This error is happening due to the version conflict in your documents. From ES official docs
Read more about how to handle the
version conflict http 409
exception in ES in this official doc, which also explains why you get the exception and various ways on how to handle it and explains the concept in details.