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

fixing ElasticsearchDocumentStore initialisation #415

Merged
merged 2 commits into from
Sep 22, 2020
Merged
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
13 changes: 13 additions & 0 deletions haystack/document_store/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,20 @@ def __init__(
self.refresh_type = refresh_type

def _create_document_index(self, index_name):
"""
Create a new index for storing documents. In case if an index with the name already exists, it ensures that
the embedding_field is present.
"""
# check if the existing index has the embedding field; if not create it
if self.client.indices.exists(index=index_name):
if self.embedding_field:
mapping = self.client.indices.get(index_name)[index_name]["mappings"]
if self.embedding_field in mapping["properties"] and mapping["properties"][self.embedding_field]["type"] != "dense_vector":
raise Exception(f"The '{index_name}' index in Elasticsearch already has a field called '{self.embedding_field}'"
f" with the type '{mapping['properties'][self.embedding_field]['type']}'. Please update the "
f"document_store to use a different name for the embedding_field parameter.")
mapping["properties"][self.embedding_field] = {"type": "dense_vector", "dims": self.embedding_dim}
self.client.indices.put_mapping(index=index_name, body=mapping)
return

if self.custom_mapping:
Expand Down