Skip to content

Commit cd6dd89

Browse files
Merge branch 'main' into optional-with-pipe-syntax
2 parents 85b67ed + 601bea7 commit cd6dd89

File tree

17 files changed

+2091
-580
lines changed

17 files changed

+2091
-580
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: Set up Python
3333
uses: actions/setup-python@v4
3434
with:
35-
python-version: "3.12"
35+
python-version: "3.13"
3636
- name: Install dependencies
3737
run: |
3838
python3 -m pip install nox
@@ -62,7 +62,7 @@ jobs:
6262
- name: Set up Python
6363
uses: actions/setup-python@v4
6464
with:
65-
python-version: "3.12"
65+
python-version: "3.x"
6666
- name: Install dependencies
6767
run: |
6868
python3 -m pip install nox
@@ -81,8 +81,9 @@ jobs:
8181
"3.10",
8282
"3.11",
8383
"3.12",
84+
"3.13",
8485
]
85-
es-version: [8.0.0, 8.13.0]
86+
es-version: [8.0.0, 8.15.0]
8687

8788
steps:
8889
- name: Remove irrelevant software to free up disk space
@@ -104,11 +105,6 @@ jobs:
104105
uses: actions/setup-python@v4
105106
with:
106107
python-version: ${{ matrix.python-version }}
107-
- name: Set up Python for Nox
108-
if: matrix.python-version != '3.12'
109-
uses: actions/setup-python@v4
110-
with:
111-
python-version: 3
112108
- name: Install dependencies
113109
run: |
114110
python3 -m pip install nox

elasticsearch_dsl/response/__init__.py

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@
4040
from ..search_base import Request, SearchBase
4141
from ..update_by_query_base import UpdateByQueryBase
4242

43-
__all__ = ["Response", "AggResponse", "UpdateByQueryResponse", "Hit", "HitMeta"]
43+
__all__ = [
44+
"Response",
45+
"AggResponse",
46+
"UpdateByQueryResponse",
47+
"Hit",
48+
"HitMeta",
49+
"AggregateResponseType",
50+
]
4451

4552

4653
class Response(AttrDict[Any], Generic[_R]):
47-
"""An Elasticsearch _search response.
54+
"""An Elasticsearch search response.
4855
4956
:arg took: (required)
5057
:arg timed_out: (required)
@@ -195,21 +202,100 @@ def search_after(self) -> "SearchBase[_R]":
195202
return self._search.extra(search_after=self.hits[-1].meta.sort) # type: ignore
196203

197204

205+
AggregateResponseType = Union[
206+
"types.CardinalityAggregate",
207+
"types.HdrPercentilesAggregate",
208+
"types.HdrPercentileRanksAggregate",
209+
"types.TDigestPercentilesAggregate",
210+
"types.TDigestPercentileRanksAggregate",
211+
"types.PercentilesBucketAggregate",
212+
"types.MedianAbsoluteDeviationAggregate",
213+
"types.MinAggregate",
214+
"types.MaxAggregate",
215+
"types.SumAggregate",
216+
"types.AvgAggregate",
217+
"types.WeightedAvgAggregate",
218+
"types.ValueCountAggregate",
219+
"types.SimpleValueAggregate",
220+
"types.DerivativeAggregate",
221+
"types.BucketMetricValueAggregate",
222+
"types.StatsAggregate",
223+
"types.StatsBucketAggregate",
224+
"types.ExtendedStatsAggregate",
225+
"types.ExtendedStatsBucketAggregate",
226+
"types.GeoBoundsAggregate",
227+
"types.GeoCentroidAggregate",
228+
"types.HistogramAggregate",
229+
"types.DateHistogramAggregate",
230+
"types.AutoDateHistogramAggregate",
231+
"types.VariableWidthHistogramAggregate",
232+
"types.StringTermsAggregate",
233+
"types.LongTermsAggregate",
234+
"types.DoubleTermsAggregate",
235+
"types.UnmappedTermsAggregate",
236+
"types.LongRareTermsAggregate",
237+
"types.StringRareTermsAggregate",
238+
"types.UnmappedRareTermsAggregate",
239+
"types.MultiTermsAggregate",
240+
"types.MissingAggregate",
241+
"types.NestedAggregate",
242+
"types.ReverseNestedAggregate",
243+
"types.GlobalAggregate",
244+
"types.FilterAggregate",
245+
"types.ChildrenAggregate",
246+
"types.ParentAggregate",
247+
"types.SamplerAggregate",
248+
"types.UnmappedSamplerAggregate",
249+
"types.GeoHashGridAggregate",
250+
"types.GeoTileGridAggregate",
251+
"types.GeoHexGridAggregate",
252+
"types.RangeAggregate",
253+
"types.DateRangeAggregate",
254+
"types.GeoDistanceAggregate",
255+
"types.IpRangeAggregate",
256+
"types.IpPrefixAggregate",
257+
"types.FiltersAggregate",
258+
"types.AdjacencyMatrixAggregate",
259+
"types.SignificantLongTermsAggregate",
260+
"types.SignificantStringTermsAggregate",
261+
"types.UnmappedSignificantTermsAggregate",
262+
"types.CompositeAggregate",
263+
"types.FrequentItemSetsAggregate",
264+
"types.TimeSeriesAggregate",
265+
"types.ScriptedMetricAggregate",
266+
"types.TopHitsAggregate",
267+
"types.InferenceAggregate",
268+
"types.StringStatsAggregate",
269+
"types.BoxPlotAggregate",
270+
"types.TopMetricsAggregate",
271+
"types.TTestAggregate",
272+
"types.RateAggregate",
273+
"types.CumulativeCardinalityAggregate",
274+
"types.MatrixStatsAggregate",
275+
"types.GeoLineAggregate",
276+
]
277+
278+
198279
class AggResponse(AttrDict[Any], Generic[_R]):
280+
"""An Elasticsearch aggregation response."""
281+
199282
_meta: Dict[str, Any]
200283

201284
def __init__(self, aggs: "Agg[_R]", search: "Request[_R]", data: Dict[str, Any]):
202285
super(AttrDict, self).__setattr__("_meta", {"search": search, "aggs": aggs})
203286
super().__init__(data)
204287

205-
def __getitem__(self, attr_name: str) -> Any:
288+
def __getitem__(self, attr_name: str) -> AggregateResponseType:
206289
if attr_name in self._meta["aggs"]:
207290
# don't do self._meta['aggs'][attr_name] to avoid copying
208291
agg = self._meta["aggs"].aggs[attr_name]
209-
return agg.result(self._meta["search"], self._d_[attr_name])
210-
return super().__getitem__(attr_name)
292+
return cast(
293+
AggregateResponseType,
294+
agg.result(self._meta["search"], self._d_[attr_name]),
295+
)
296+
return super().__getitem__(attr_name) # type: ignore
211297

212-
def __iter__(self) -> Iterator["Agg"]: # type: ignore[override]
298+
def __iter__(self) -> Iterator[AggregateResponseType]: # type: ignore[override]
213299
for name in self._meta["aggs"]:
214300
yield self[name]
215301

0 commit comments

Comments
 (0)