diff --git a/elasticsearch_dsl/document.py b/elasticsearch_dsl/document.py index 6a3aa2b49..42b9b3fdd 100644 --- a/elasticsearch_dsl/document.py +++ b/elasticsearch_dsl/document.py @@ -406,7 +406,7 @@ def update( doc_meta["retry_on_conflict"] = retry_on_conflict # Optimistic concurrency control - if "seq_no" in self.meta and "primary_term" in self.meta: + if retry_on_conflict in (None, 0) and "seq_no" in self.meta and "primary_term" in self.meta: doc_meta["if_seq_no"] = self.meta["seq_no"] doc_meta["if_primary_term"] = self.meta["primary_term"] diff --git a/tests/test_integration/test_document.py b/tests/test_integration/test_document.py index 83932f7e5..fad6efa8f 100644 --- a/tests/test_integration/test_document.py +++ b/tests/test_integration/test_document.py @@ -234,6 +234,20 @@ def test_update_script(write_client): assert w.views == 47 +def test_update_retry_on_conflict(write_client): + Wiki.init() + w = Wiki(owner=User(name="Honza Kral"), _id="elasticsearch-py", views=42) + w.save() + + w1 = Wiki.get(id="elasticsearch-py") + w2 = Wiki.get(id="elasticsearch-py") + w1.update(script="ctx._source.views += params.inc", inc=5, retry_on_conflict=1) + w2.update(script="ctx._source.views += params.inc", inc=5, retry_on_conflict=1) + + w = Wiki.get(id="elasticsearch-py") + assert w.views == 52 + + def test_save_and_update_return_doc_meta(write_client): Wiki.init() w = Wiki(owner=User(name="Honza Kral"), _id="elasticsearch-py", views=42)