Skip to content

Commit 18e596e

Browse files
buckets_as_dict property
1 parent 1caae1d commit 18e596e

File tree

5 files changed

+201
-57
lines changed

5 files changed

+201
-57
lines changed

elasticsearch_dsl/response/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
Optional,
2727
Sequence,
2828
Tuple,
29-
TypedDict,
3029
Union,
3130
cast,
3231
)
@@ -196,7 +195,7 @@ def search_after(self) -> "SearchBase[_R]":
196195
return self._search.extra(search_after=self.hits[-1].meta.sort) # type: ignore
197196

198197

199-
_Aggregate = Union[
198+
AggregateResponseType = Union[
200199
"types.CardinalityAggregate",
201200
"types.HdrPercentilesAggregate",
202201
"types.HdrPercentileRanksAggregate",
@@ -268,28 +267,28 @@ def search_after(self) -> "SearchBase[_R]":
268267
"types.MatrixStatsAggregate",
269268
"types.GeoLineAggregate",
270269
]
271-
_AggResponseMeta = TypedDict(
272-
"_AggResponseMeta", {"search": "Request[_R]", "aggs": Mapping[str, _Aggregate]}
273-
)
274270

275271

276272
class AggResponse(AttrDict[Any], Generic[_R]):
273+
"""An Elasticsearch aggregation response."""
274+
277275
_meta: Dict[str, Any]
278276

279277
def __init__(self, aggs: "Agg[_R]", search: "Request[_R]", data: Dict[str, Any]):
280278
super(AttrDict, self).__setattr__("_meta", {"search": search, "aggs": aggs})
281279
super().__init__(data)
282280

283-
def __getitem__(self, attr_name: str) -> _Aggregate:
281+
def __getitem__(self, attr_name: str) -> AggregateResponseType:
284282
if attr_name in self._meta["aggs"]:
285283
# don't do self._meta['aggs'][attr_name] to avoid copying
286284
agg = self._meta["aggs"].aggs[attr_name]
287285
return cast(
288-
_Aggregate, agg.result(self._meta["search"], self._d_[attr_name])
286+
AggregateResponseType,
287+
agg.result(self._meta["search"], self._d_[attr_name]),
289288
)
290289
return super().__getitem__(attr_name) # type: ignore
291290

292-
def __iter__(self) -> Iterator[_Aggregate]: # type: ignore[override]
291+
def __iter__(self) -> Iterator[AggregateResponseType]: # type: ignore[override]
293292
for name in self._meta["aggs"]:
294293
yield self[name]
295294

0 commit comments

Comments
 (0)