Elasticsearch "version_conflict_engine_exception" in CI
Elasticsearch rejected a write because the document version it was given did not match the current version. This optimistic-concurrency guard fires when two writes race, when a create request targets an id that already exists, or when a test reuses a stale sequence number.
What this error means
An index, update, or delete returns HTTP 409 with "version_conflict_engine_exception", mentioning the current and required primary term or sequence number.
{"error":{"root_cause":[{"type":"version_conflict_engine_exception","reason":
"[1]: version conflict, required seqNo [5], primary term [1]. current document has
seqNo [7] and primary term [1]"}],"type":"version_conflict_engine_exception"},"status":409}Common causes
Concurrent writes to the same document
Two updates race on the same id; the second carries a sequence number that is already stale, so it is rejected.
A create request hit an existing id
An op_type=create (or _create) request against an id left over from a previous run conflicts with the existing document.
How to fix it
Reset state and avoid id reuse between runs
- Delete or recreate the index so leftover ids do not collide.
- Use unique ids per test, or let Elasticsearch auto-generate them.
- Refresh between dependent writes so reads see the latest version.
curl -X DELETE "http://localhost:9200/orders"
curl -X PUT "http://localhost:9200/orders"Retry on conflict for concurrent updates
For update-by-query or update requests, set retry_on_conflict so a losing writer retries against the current version instead of failing.
POST /orders/_update/1?retry_on_conflict=3
{"doc":{"status":"paid"}}How to prevent it
- Start each run from a clean index so document ids do not carry over.
- Use auto-generated ids or per-test unique ids.
- Set
retry_on_conflicton updates that can race.