diff --git a/haystack/document_stores/opensearch.py b/haystack/document_stores/opensearch.py index ff54efb14..6f402498d 100644 --- a/haystack/document_stores/opensearch.py +++ b/haystack/document_stores/opensearch.py @@ -745,10 +745,11 @@ class OpenSearchDocumentStore(SearchEngineDocumentStore): :return: None """ # Check if index uses an IVF model and delete it - index_mapping = self.client.indices.get(index)[index]["mappings"]["properties"] - if self.embedding_field in index_mapping and "model_id" in index_mapping[self.embedding_field]: - model_id = index_mapping[self.embedding_field]["model_id"] - self.client.transport.perform_request("DELETE", f"/_plugins/_knn/models/{model_id}") + if self._index_exists(index): + index_mapping = self.client.indices.get(index)[index]["mappings"]["properties"] + if self.embedding_field in index_mapping and "model_id" in index_mapping[self.embedding_field]: + model_id = index_mapping[self.embedding_field]["model_id"] + self.client.transport.perform_request("DELETE", f"/_plugins/_knn/models/{model_id}") super().delete_index(index) diff --git a/haystack/testing/document_store.py b/haystack/testing/document_store.py index 8a307f5a6..6e12da675 100644 --- a/haystack/testing/document_store.py +++ b/haystack/testing/document_store.py @@ -478,6 +478,10 @@ class DocumentStoreBaseTestAbstract: with pytest.raises(Exception): ds.get_document_count(index="custom_index") + @pytest.mark.integration + def test_delete_index_does_not_raise_if_not_exists(self, ds): + ds.delete_index(index="unknown_index") + @pytest.mark.integration def test_update_meta(self, ds, documents): ds.write_documents(documents)