Skip to content

Commit 579f572

Browse files
Generate types for the Elasticsearch responses (#1929)
* generate types for the Elasticsearch response * typing of the update by query response * minor typing updates * Update utils/templates/response.__init__.py.tpl Co-authored-by: Quentin Pradet <[email protected]> --------- Co-authored-by: Quentin Pradet <[email protected]>
1 parent e001424 commit 579f572

File tree

10 files changed

+3470
-2368
lines changed

10 files changed

+3470
-2368
lines changed

elasticsearch_dsl/document_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def __init__(self, name: str, bases: Tuple[type, ...], attrs: Dict[str, Any]):
165165
fields.update(annotations.keys())
166166
field_defaults = {}
167167
for name in fields:
168-
value = None
168+
value: Any = None
169169
required = None
170170
multi = None
171171
if name in annotations:
@@ -201,7 +201,7 @@ def __init__(self, name: str, bases: Tuple[type, ...], attrs: Dict[str, Any]):
201201
field_args = [type_]
202202
elif type_ in self.type_annotation_map:
203203
# use best field type for the type hint provided
204-
field, field_kwargs = self.type_annotation_map[type_]
204+
field, field_kwargs = self.type_annotation_map[type_] # type: ignore
205205

206206
if field:
207207
field_kwargs = {

elasticsearch_dsl/response/__init__.py

+76
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
Generic,
2323
Iterator,
2424
List,
25+
Mapping,
2526
Optional,
27+
Sequence,
2628
Tuple,
2729
Union,
2830
cast,
@@ -32,6 +34,7 @@
3234
from .hit import Hit, HitMeta
3335

3436
if TYPE_CHECKING:
37+
from .. import types
3538
from ..aggs import Agg
3639
from ..faceted_search_base import FacetedSearchBase
3740
from ..search_base import Request, SearchBase
@@ -41,11 +44,47 @@
4144

4245

4346
class Response(AttrDict[Any], Generic[_R]):
47+
"""An Elasticsearch response.
48+
49+
:arg took: (required)
50+
:arg timed_out: (required)
51+
:arg _shards: (required)
52+
:arg hits: search results
53+
:arg aggregations: aggregation results
54+
:arg _clusters:
55+
:arg fields:
56+
:arg max_score:
57+
:arg num_reduce_phases:
58+
:arg profile:
59+
:arg pit_id:
60+
:arg _scroll_id:
61+
:arg suggest:
62+
:arg terminated_early:
63+
"""
64+
4465
_search: "SearchBase[_R]"
4566
_faceted_search: "FacetedSearchBase[_R]"
4667
_doc_class: Optional[_R]
4768
_hits: List[_R]
4869

70+
took: int
71+
timed_out: bool
72+
_shards: "types.ShardStatistics"
73+
_clusters: "types.ClusterStatistics"
74+
fields: Mapping[str, Any]
75+
max_score: float
76+
num_reduce_phases: int
77+
profile: "types.Profile"
78+
pit_id: str
79+
_scroll_id: str
80+
suggest: Mapping[
81+
str,
82+
Sequence[
83+
Union["types.CompletionSuggest", "types.PhraseSuggest", "types.TermSuggest"]
84+
],
85+
]
86+
terminated_early: bool
87+
4988
def __init__(
5089
self,
5190
search: "Request[_R]",
@@ -176,8 +215,45 @@ def __iter__(self) -> Iterator["Agg"]: # type: ignore[override]
176215

177216

178217
class UpdateByQueryResponse(AttrDict[Any], Generic[_R]):
218+
"""An Elasticsearch update by query response.
219+
220+
:arg batches:
221+
:arg failures:
222+
:arg noops:
223+
:arg deleted:
224+
:arg requests_per_second:
225+
:arg retries:
226+
:arg task:
227+
:arg timed_out:
228+
:arg took:
229+
:arg total:
230+
:arg updated:
231+
:arg version_conflicts:
232+
:arg throttled:
233+
:arg throttled_millis:
234+
:arg throttled_until:
235+
:arg throttled_until_millis:
236+
"""
237+
179238
_search: "UpdateByQueryBase[_R]"
180239

240+
batches: int
241+
failures: Sequence["types.BulkIndexByScrollFailure"]
242+
noops: int
243+
deleted: int
244+
requests_per_second: float
245+
retries: "types.Retries"
246+
task: Union[str, int]
247+
timed_out: bool
248+
took: Any
249+
total: int
250+
updated: int
251+
version_conflicts: int
252+
throttled: Any
253+
throttled_millis: Any
254+
throttled_until: Any
255+
throttled_until_millis: Any
256+
181257
def __init__(
182258
self,
183259
search: "Request[_R]",

0 commit comments

Comments
 (0)