Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opensearch errors bulk write #594

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}")