Skip to content

Commit c43c5e3

Browse files
typing of the update by query response
1 parent 6c32f9a commit c43c5e3

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

elasticsearch_dsl/response/__init__.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,45 @@ def __iter__(self) -> Iterator["Agg"]: # type: ignore[override]
215215

216216

217217
class UpdateByQueryResponse(AttrDict[Any], Generic[_R]):
218+
"""An Elasticsearch 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+
218238
_search: "UpdateByQueryBase[_R]"
219239

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+
220257
def __init__(
221258
self,
222259
search: "Request[_R]",

elasticsearch_dsl/types.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4458,6 +4458,22 @@ class AggregationProfileDelegateDebugFilter(AttrDict[Any]):
44584458
segments_counted_in_constant_time: int
44594459

44604460

4461+
class BulkIndexByScrollFailure(AttrDict[Any]):
4462+
"""
4463+
:arg cause: (required)
4464+
:arg id: (required)
4465+
:arg index: (required)
4466+
:arg status: (required)
4467+
:arg type: (required)
4468+
"""
4469+
4470+
cause: "ErrorCause"
4471+
id: str
4472+
index: str
4473+
status: int
4474+
type: str
4475+
4476+
44614477
class ClusterDetails(AttrDict[Any]):
44624478
"""
44634479
:arg status: (required)
@@ -4884,6 +4900,16 @@ class QueryProfile(AttrDict[Any]):
48844900
children: Sequence["QueryProfile"]
48854901

48864902

4903+
class Retries(AttrDict[Any]):
4904+
"""
4905+
:arg bulk: (required)
4906+
:arg search: (required)
4907+
"""
4908+
4909+
bulk: int
4910+
search: int
4911+
4912+
48874913
class SearchProfile(AttrDict[Any]):
48884914
"""
48894915
:arg collector: (required)

utils/generator.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,12 @@ def interface_to_python_class(
638638
```
639639
"""
640640
type_ = self.find_type(interface, namespace)
641-
if type_["kind"] != "interface":
641+
if type_["kind"] not in ["interface", "response"]:
642642
raise RuntimeError(f"Type {interface} is not an interface")
643+
if type_["kind"] == "response":
644+
# we consider responses as interfaces because they also have properties
645+
# but the location of the properties is different
646+
type_ = type_["body"]
643647
k = {"name": interface, "for_response": for_response, "args": []}
644648
self.add_behaviors(
645649
type_, k, for_types_py=for_types_py, for_response=for_response
@@ -718,14 +722,22 @@ def generate_response_init_py(schema, filename):
718722
"""Generate response/__init__.py with all the response properties
719723
documented and typed.
720724
"""
721-
response_interface = schema.interface_to_python_class(
725+
search_response = schema.interface_to_python_class(
722726
"ResponseBody",
723727
"_global.search",
724728
for_types_py=False,
725729
for_response=True,
726730
)
731+
ubq_response = schema.interface_to_python_class(
732+
"Response",
733+
"_global.update_by_query",
734+
for_types_py=False,
735+
for_response=True,
736+
)
727737
with open(filename, "wt") as f:
728-
f.write(response_init_py.render(response=response_interface))
738+
f.write(
739+
response_init_py.render(response=search_response, ubq_response=ubq_response)
740+
)
729741
print(f"Generated {filename}.")
730742

731743

utils/templates/response.__init__.py.tpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,20 @@ class AggResponse(AttrDict[Any], Generic[_R]):
193193

194194

195195
class UpdateByQueryResponse(AttrDict[Any], Generic[_R]):
196+
"""An Elasticsearch response.
197+
198+
{% for arg in ubq_response.args %}
199+
{% for line in arg.doc %}
200+
{{ line }}
201+
{% endfor %}
202+
{% endfor %}
203+
"""
196204
_search: "UpdateByQueryBase[_R]"
197205

206+
{% for arg in ubq_response.args %}
207+
{{ arg.name }}: {{ arg.type }}
208+
{% endfor %}
209+
198210
def __init__(
199211
self,
200212
search: "Request[_R]",

0 commit comments

Comments
 (0)