BUGFIX: Support for elastic indices that don't return 'metadata' in '_source' (#13903)

Description: Some Elastic indexes do not return a 'metadata' field in
'_source'. However, prior to this PR, the code assumed there always is a
'metadata' field. This PR adds support for cases where the field is
missing by adding it manually.

Issue: #13869
This commit is contained in:
Assaf Toledo 2023-11-27 22:52:57 +02:00 committed by GitHub
parent c156d0281a
commit ba62ff89cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -798,6 +798,8 @@ class ElasticsearchStore(VectorStore):
"metadata",
self.query_field,
]:
if "metadata" not in hit["_source"]:
hit["_source"]["metadata"] = {}
hit["_source"]["metadata"][field] = hit["_source"][field]
docs_and_scores.append(