409 - version conflict - delete_by_query (API request using C# NEST)

Status: 409
Type: version_conflict_engine_exception
Reason: [My_Doc_ID]: version conflict, required seqNo [5092680], primary term [45].
current document has seqNo [5095726] and primary term [45]

We are using C# Nest library to ingest documents. In this instance I am trying to delete documents that are no longer current with a delete_by_query request using a DateRange LessThan parameter.

The query works without issue in our development and test environments but has been failing in our production environment. Might it relate to cluster/replication configuration?

Searching the forums I found a topic that mentions version conflict being a result of too many Kibana windows open but I don't think that's relevant here.

Which version of Elasticsearch are you using? Are you running more than one concurrent delete task? Are you performing updates on your documents?

version 8.6.1. In the production environment, there may be other delete tasks running against the same index but not against the same documents. Prior to the delete_by_query our process will have been updating documents.

I have added a line of code to our software to pause for 15 seconds before it sends the delete_by_query, after it has completed sending requests to update the documents. :crossed_fingers:

Better than waiting an arbitrary interval is probably to send a refresh API request before initiating the update.

Will take a look at that option, thank you.

The documents we are deleting would not be amongst any that have recently been updated but other users might potentially be carrying out queries that would include both the recently updated documents and those we are about to delete.

I could call the refresh with the optional refresh=wait_for parameter prior to my 15 second pause. I am obviously keen to avoid doing anything resource-intensive.

Refreshes are resource-intensive. To ensure good cluster performance, we recommend waiting for Elasticsearch’s periodic refresh rather than performing an explicit refresh when possible.

If your application workflow indexes documents and then runs a search to retrieve the indexed document, we recommend using the index API's refresh=wait_for query parameter option. This option ensures the indexing operation waits for a periodic refresh before running the search.

You should avoid performing refreshes for every update, but doing it once before starting the update adds no more load than waiting for it to happen by itself.

Thank you.

A quick Stack search suggests this is how the refresh API request is exposed by the C# Nest library...

await elasticClient.Indices.RefreshAsync("index_name");

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.