Skip to content

Commit 43d53b5

Browse files
committed
Generate new structure to accept body again
1 parent c3b8bb8 commit 43d53b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+5306
-3538
lines changed

elasticsearch/_async/client/__init__.py

Lines changed: 430 additions & 288 deletions
Large diffs are not rendered by default.

elasticsearch/_async/client/async_search.py

Lines changed: 104 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,41 @@ async def status(
155155
)
156156

157157
@_rewrite_parameters(
158-
body_fields=True,
158+
body_fields=(
159+
"aggregations",
160+
"aggs",
161+
"collapse",
162+
"docvalue_fields",
163+
"explain",
164+
"ext",
165+
"fields",
166+
"from_",
167+
"highlight",
168+
"indices_boost",
169+
"knn",
170+
"min_score",
171+
"pit",
172+
"post_filter",
173+
"profile",
174+
"query",
175+
"rescore",
176+
"runtime_mappings",
177+
"script_fields",
178+
"search_after",
179+
"seq_no_primary_term",
180+
"size",
181+
"slice",
182+
"sort",
183+
"source",
184+
"stats",
185+
"stored_fields",
186+
"suggest",
187+
"terminate_after",
188+
"timeout",
189+
"track_scores",
190+
"track_total_hits",
191+
"version",
192+
),
159193
parameter_aliases={
160194
"_source": "source",
161195
"_source_excludes": "source_excludes",
@@ -260,6 +294,7 @@ async def submit(
260294
wait_for_completion_timeout: t.Optional[
261295
t.Union["t.Literal[-1]", "t.Literal[0]", str]
262296
] = None,
297+
body: t.Optional[t.Dict[str, t.Any]] = None,
263298
) -> ObjectApiResponse[t.Any]:
264299
"""
265300
Executes a search request asynchronously.
@@ -397,7 +432,7 @@ async def submit(
397432
else:
398433
__path = "/_async_search"
399434
__query: t.Dict[str, t.Any] = {}
400-
__body: t.Dict[str, t.Any] = {}
435+
__body: t.Dict[str, t.Any] = body if body is not None else {}
401436
# The 'sort' parameter with a colon can't be encoded to the body.
402437
if sort is not None and (
403438
(isinstance(sort, str) and ":" in sort)
@@ -481,72 +516,73 @@ async def submit(
481516
__query["typed_keys"] = typed_keys
482517
if wait_for_completion_timeout is not None:
483518
__query["wait_for_completion_timeout"] = wait_for_completion_timeout
484-
if aggregations is not None:
485-
__body["aggregations"] = aggregations
486-
if aggs is not None:
487-
__body["aggs"] = aggs
488-
if collapse is not None:
489-
__body["collapse"] = collapse
490-
if docvalue_fields is not None:
491-
__body["docvalue_fields"] = docvalue_fields
492-
if explain is not None:
493-
__body["explain"] = explain
494-
if ext is not None:
495-
__body["ext"] = ext
496-
if fields is not None:
497-
__body["fields"] = fields
498-
if from_ is not None:
499-
__body["from"] = from_
500-
if highlight is not None:
501-
__body["highlight"] = highlight
502-
if indices_boost is not None:
503-
__body["indices_boost"] = indices_boost
504-
if knn is not None:
505-
__body["knn"] = knn
506-
if min_score is not None:
507-
__body["min_score"] = min_score
508-
if pit is not None:
509-
__body["pit"] = pit
510-
if post_filter is not None:
511-
__body["post_filter"] = post_filter
512-
if profile is not None:
513-
__body["profile"] = profile
514-
if query is not None:
515-
__body["query"] = query
516-
if rescore is not None:
517-
__body["rescore"] = rescore
518-
if runtime_mappings is not None:
519-
__body["runtime_mappings"] = runtime_mappings
520-
if script_fields is not None:
521-
__body["script_fields"] = script_fields
522-
if search_after is not None:
523-
__body["search_after"] = search_after
524-
if seq_no_primary_term is not None:
525-
__body["seq_no_primary_term"] = seq_no_primary_term
526-
if size is not None:
527-
__body["size"] = size
528-
if slice is not None:
529-
__body["slice"] = slice
530-
if sort is not None:
531-
__body["sort"] = sort
532-
if source is not None:
533-
__body["_source"] = source
534-
if stats is not None:
535-
__body["stats"] = stats
536-
if stored_fields is not None:
537-
__body["stored_fields"] = stored_fields
538-
if suggest is not None:
539-
__body["suggest"] = suggest
540-
if terminate_after is not None:
541-
__body["terminate_after"] = terminate_after
542-
if timeout is not None:
543-
__body["timeout"] = timeout
544-
if track_scores is not None:
545-
__body["track_scores"] = track_scores
546-
if track_total_hits is not None:
547-
__body["track_total_hits"] = track_total_hits
548-
if version is not None:
549-
__body["version"] = version
519+
if not __body:
520+
if aggregations is not None:
521+
__body["aggregations"] = aggregations
522+
if aggs is not None:
523+
__body["aggs"] = aggs
524+
if collapse is not None:
525+
__body["collapse"] = collapse
526+
if docvalue_fields is not None:
527+
__body["docvalue_fields"] = docvalue_fields
528+
if explain is not None:
529+
__body["explain"] = explain
530+
if ext is not None:
531+
__body["ext"] = ext
532+
if fields is not None:
533+
__body["fields"] = fields
534+
if from_ is not None:
535+
__body["from"] = from_
536+
if highlight is not None:
537+
__body["highlight"] = highlight
538+
if indices_boost is not None:
539+
__body["indices_boost"] = indices_boost
540+
if knn is not None:
541+
__body["knn"] = knn
542+
if min_score is not None:
543+
__body["min_score"] = min_score
544+
if pit is not None:
545+
__body["pit"] = pit
546+
if post_filter is not None:
547+
__body["post_filter"] = post_filter
548+
if profile is not None:
549+
__body["profile"] = profile
550+
if query is not None:
551+
__body["query"] = query
552+
if rescore is not None:
553+
__body["rescore"] = rescore
554+
if runtime_mappings is not None:
555+
__body["runtime_mappings"] = runtime_mappings
556+
if script_fields is not None:
557+
__body["script_fields"] = script_fields
558+
if search_after is not None:
559+
__body["search_after"] = search_after
560+
if seq_no_primary_term is not None:
561+
__body["seq_no_primary_term"] = seq_no_primary_term
562+
if size is not None:
563+
__body["size"] = size
564+
if slice is not None:
565+
__body["slice"] = slice
566+
if sort is not None:
567+
__body["sort"] = sort
568+
if source is not None:
569+
__body["_source"] = source
570+
if stats is not None:
571+
__body["stats"] = stats
572+
if stored_fields is not None:
573+
__body["stored_fields"] = stored_fields
574+
if suggest is not None:
575+
__body["suggest"] = suggest
576+
if terminate_after is not None:
577+
__body["terminate_after"] = terminate_after
578+
if timeout is not None:
579+
__body["timeout"] = timeout
580+
if track_scores is not None:
581+
__body["track_scores"] = track_scores
582+
if track_total_hits is not None:
583+
__body["track_total_hits"] = track_total_hits
584+
if version is not None:
585+
__body["version"] = version
550586
if not __body:
551587
__body = None # type: ignore[assignment]
552588
__headers = {"accept": "application/json"}

elasticsearch/_async/client/autoscaling.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ async def put_autoscaling_policy(
131131
self,
132132
*,
133133
name: str,
134-
policy: t.Mapping[str, t.Any],
134+
policy: t.Optional[t.Mapping[str, t.Any]] = None,
135+
body: t.Optional[t.Mapping[str, t.Any]] = None,
135136
error_trace: t.Optional[bool] = None,
136137
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
137138
human: t.Optional[bool] = None,
@@ -148,8 +149,12 @@ async def put_autoscaling_policy(
148149
"""
149150
if name in SKIP_IN_PATH:
150151
raise ValueError("Empty value passed for parameter 'name'")
151-
if policy is None:
152-
raise ValueError("Empty value passed for parameter 'policy'")
152+
if policy is None and body is None:
153+
raise ValueError(
154+
"Empty value passed for parameters 'policy' and 'body', one of them should be set."
155+
)
156+
elif policy is not None and body is not None:
157+
raise ValueError("Cannot set both 'policy' and 'body'")
153158
__path = f"/_autoscaling/policy/{_quote(name)}"
154159
__query: t.Dict[str, t.Any] = {}
155160
if error_trace is not None:
@@ -160,7 +165,7 @@ async def put_autoscaling_policy(
160165
__query["human"] = human
161166
if pretty is not None:
162167
__query["pretty"] = pretty
163-
__body = policy
168+
__body = policy if policy is not None else body
164169
__headers = {"accept": "application/json", "content-type": "application/json"}
165170
return await self.perform_request( # type: ignore[return-value]
166171
"PUT", __path, params=__query, headers=__headers, body=__body

0 commit comments

Comments
 (0)