Skip to content

Commit

Permalink
Added the synonym analyser for search fields
Browse files Browse the repository at this point in the history
  • Loading branch information
SjSnowball committed Jan 28, 2022
1 parent e6d5af8 commit 51d15e3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion haystack/document_stores/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,13 @@ def _create_document_index(self, index_name: str, headers: Optional[Dict[str, st
}
}
if self.search_fields:
if self.synonyms:
search_fields_mapping = {"type": "text", "analyzer": "synonym"}
else:
search_fields_mapping = {"type": "text"}

for field in self.search_fields:
mapping["mappings"]["properties"].update({field: {"type": "text"}})
mapping["mappings"]["properties"].update({field: search_fields_mapping})

if self.synonyms:
mapping["mappings"]["properties"][self.content_field] = {"type": "text", "analyzer": "synonym"}
Expand Down

0 comments on commit 51d15e3

Please sign in to comment.