Skip to content

Commit

Permalink
Fix opensearch errors bulk write (#594)
Browse files Browse the repository at this point in the history
* fix(opensearch): bulk error without create key

* Add test

* Comment why

---------

Co-authored-by: Corentin Meyer <[email protected]>
  • Loading branch information
silvanocerza and lambda-science authored Mar 18, 2024
1 parent 48fe102 commit 6d21ba0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ def write_documents(self, documents: List[Document], policy: DuplicatePolicy = D
duplicate_errors_ids = []
other_errors = []
for e in errors:
# OpenSearch might not return a correctly formatted error, in that case we
# treat it as a generic error
if "create" not in e:
other_errors.append(e)
continue
error_type = e["create"]["error"]["type"]
if policy == DuplicatePolicy.FAIL and error_type == "version_conflict_engine_exception":
duplicate_errors_ids.append(e["create"]["_id"])
Expand Down
9 changes: 9 additions & 0 deletions integrations/opensearch/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,12 @@ def test_write_documents_different_embedding_sizes_fail(

with pytest.raises(DocumentStoreError):
document_store_embedding_dim_4.write_documents(docs)

@patch("haystack_integrations.document_stores.opensearch.document_store.bulk")
def test_write_documents_with_badly_formatted_bulk_errors(self, mock_bulk, document_store):
error = {"some_key": "some_value"}
mock_bulk.return_value = ([], [error])

with pytest.raises(DocumentStoreError) as e:
document_store.write_documents([Document(content="Hello world")])
e.match(f"{error}")

0 comments on commit 6d21ba0

Please sign in to comment.