From 4cf83e96d5a610fb57ceebd647070100a6a6e939 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 7e775eb..e9fc09e 100644 --- a/invenio_stats/aggregations.py +++ b/invenio_stats/aggregations.py @@ -339,7 +339,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))