question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I use retry_on_conflict to resolve error "ConflictError 409" with update()?

See original GitHub issue

I noticed that if I send too many requests in a short period, my elasticsearch update code throws a 409 ConflictError. Reading a bit into it, I noticed there is a param for update() to set the number of retry attempts, however when I tried using it, I get another error:

RequestError(400, 'action_request_validation_exception', 'Validation Failed: 1: compare and write operations can not be retried;')

How can I handle 409 ConflictError during frequent updates and/or use the retry_on_conflict param?

    thing = Thing.get(id=thing_id, ignore=404)

    if thing:
            return post.update(
                script=update_func,
                refresh=True,
                retry_on_conflict=ES_UPDATE_RETRY_COUNT,
                now=arrow.utcnow().float_timestamp,
            )
ConflictError: ConflictError(409, 'version_conflict_engine_exception', '[TtWP-la58FPHbw]: version conflict, required seqNo [8], primary term [1]. current document has seqNo [9] and primary term [1]')
(2 additional frame(s) were not displaye

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
hoIIercommented, Mar 27, 2020

using elasticsearch-py directly seems to work…

            return post._get_connection().update(
                Post.Index().name,
                post_id,
                body,
                refresh=True,
                retry_on_conflict=10,
            )
0reactions
ryonakamuracommented, Nov 10, 2020

This error seems to occur when adding if_seq_no and if_primary_term to the update arguments.

https://github.com/elastic/elasticsearch-dsl-py/blob/7.3.0/elasticsearch_dsl/document.py#L407

Here’s a temporary solution:

del post.meta['seq_no']
del post.meta['primary_term']
post.update(
    retry_on_conflict=10,
    date=datetime.utcnow(),
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Version conflict when using the delete method of elasticsearch ...
This error is happening due to the version conflict in your documents. From ES official docs. Elasticsearch is distributed.
Read more >
retry - Go Packages
RetryOnConflict is used to make an update to a resource when you have to worry about conflicts caused by other code making unrelated...
Read more >
Developer Guide to Kubernetes Clients, Caches, Conflicts, etc.
Let's take a look at the different types of Kubernetes clients in go ... if there were concurrent updates to the object (conflict...
Read more >
Couldn't resolve version – How to solve this Elasticsearch error
Common problems. If optimistic locking is not implemented while making updates to a document, Elasticsearch may return a conflict error with the 409...
Read more >
How to fix Escenic content studio 409 conflict error - YouTube
Sometimes the java cache causes issues with escenic when you try to save things, here is how to fix that in simple and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found