diff --git a/integrations/opensearch/src/haystack_integrations/document_stores/opensearch/document_store.py b/integrations/opensearch/src/haystack_integrations/document_stores/opensearch/document_store.py index 496d22ea0..71befb2fe 100644 --- a/integrations/opensearch/src/haystack_integrations/document_stores/opensearch/document_store.py +++ b/integrations/opensearch/src/haystack_integrations/document_stores/opensearch/document_store.py @@ -119,10 +119,15 @@ def client(self) -> OpenSearch: elif self._create_index: # Create the index if it doesn't exist body = {"mappings": self._mappings, "settings": self._settings} - self._client.indices.create(index=self._index, body=body) + self._client.indices.create(index=self._index, body=body) # type:ignore return self._client - - def create_index(self, index: Optional[str] = None, mappings: Optional[Dict[str, Any]] = None, settings: Optional[Dict[str, Any]] = None) -> None: + + def create_index( + self, + index: Optional[str] = None, + mappings: Optional[Dict[str, Any]] = None, + settings: Optional[Dict[str, Any]] = None, + ) -> None: """ Creates an index in OpenSearch. @@ -141,7 +146,7 @@ def create_index(self, index: Optional[str] = None, mappings: Optional[Dict[str, mappings = self._mappings if not settings: settings = self._settings - + if not self.client.indices.exists(index=index): self.client.indices.create(index=index, body={"mappings": mappings, "settings": settings}) diff --git a/integrations/opensearch/tests/test_document_store.py b/integrations/opensearch/tests/test_document_store.py index 024ff94f1..51fc23a6e 100644 --- a/integrations/opensearch/tests/test_document_store.py +++ b/integrations/opensearch/tests/test_document_store.py @@ -207,7 +207,7 @@ def test_write_documents_readonly(self, document_store_readonly: OpenSearchDocum def test_create_index(self, document_store_readonly: OpenSearchDocumentStore): document_store_readonly.create_index() - assert document_store_readonly.client.indices.exists(index=document_store_readonly.index) + assert document_store_readonly.client.indices.exists(index=document_store_readonly._index) def test_bm25_retrieval(self, document_store: OpenSearchDocumentStore): document_store.write_documents(