Fix filters in query_embedding for ElasticsearchDocumentStore (#464)

Co-authored-by: Pierre Pereira <pierre.pereira@lexistems.com>
This commit is contained in:
Futurne 2020-10-05 11:25:07 +02:00 committed by GitHub
parent 669c72d538
commit 072e32b38a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -437,14 +437,13 @@ class ElasticsearchDocumentStore(BaseDocumentStore):
} # type: Dict[str,Any]
if filters:
filter_clause = []
for key, values in filters.items():
filter_clause.append(
{
"terms": {key: values}
if type(values) != list:
raise ValueError(f'Wrong filter format for key "{key}": Please provide a list of allowed values for each key. '
'Example: {"name": ["some", "more"], "category": ["only_one"]} ')
body["query"]["script_score"]["query"] = {
"terms": filters
}
)
body["query"]["bool"]["filter"] = filter_clause
if self.excluded_meta_data:
body["_source"] = {"excludes": self.excluded_meta_data}