From 95082d70b7bacecd9f45ee885c6b510ed2ee617f Mon Sep 17 00:00:00 2001 From: Maximilian Moser Date: Thu, 23 Feb 2023 14:41:18 +0100 Subject: [PATCH] aggregations: turn agg query results into dictionaries * because we're reusing parts of the aggregation query results directly, and per default they're wrapped in DSL objects (e.g. AttrList) that aren't JSON-serializable * see: https://github.com/elastic/elasticsearch-dsl-py/issues/913 --- invenio_stats/aggregations.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/invenio_stats/aggregations.py b/invenio_stats/aggregations.py index 737cea2..21a1b17 100644 --- a/invenio_stats/aggregations.py +++ b/invenio_stats/aggregations.py @@ -341,7 +341,8 @@ def agg_iter(self, dt): ignore_cache=True, ) for aggregation in results.aggregations["terms"].buckets: - doc = aggregation.top_hit.hits.hits[0]["_source"] + doc = aggregation.top_hit.hits.hits[0]["_source"].to_dict() + aggregation = aggregation.to_dict() interval_date = datetime.strptime( doc["timestamp"], "%Y-%m-%dT%H:%M:%S" ).replace(**dict.fromkeys(INTERVAL_ROUNDING[self.interval], 0))