Skip to content

Commit f16d183

Browse files
committed
Generate new structure to accept body again
1 parent dc96930 commit f16d183

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

+5530
-3750
lines changed

elasticsearch/_async/client/__init__.py

Lines changed: 446 additions & 304 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.
@@ -396,8 +431,8 @@ async def submit(
396431
__path = f"/{_quote(index)}/_async_search"
397432
else:
398433
__path = "/_async_search"
399-
__body: t.Dict[str, t.Any] = {}
400434
__query: 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)
@@ -409,10 +444,6 @@ async def submit(
409444
):
410445
__query["sort"] = sort
411446
sort = None
412-
if aggregations is not None:
413-
__body["aggregations"] = aggregations
414-
if aggs is not None:
415-
__body["aggs"] = aggs
416447
if allow_no_indices is not None:
417448
__query["allow_no_indices"] = allow_no_indices
418449
if allow_partial_search_results is not None:
@@ -425,106 +456,54 @@ async def submit(
425456
__query["batched_reduce_size"] = batched_reduce_size
426457
if ccs_minimize_roundtrips is not None:
427458
__query["ccs_minimize_roundtrips"] = ccs_minimize_roundtrips
428-
if collapse is not None:
429-
__body["collapse"] = collapse
430459
if default_operator is not None:
431460
__query["default_operator"] = default_operator
432461
if df is not None:
433462
__query["df"] = df
434-
if docvalue_fields is not None:
435-
__body["docvalue_fields"] = docvalue_fields
436463
if error_trace is not None:
437464
__query["error_trace"] = error_trace
438465
if expand_wildcards is not None:
439466
__query["expand_wildcards"] = expand_wildcards
440-
if explain is not None:
441-
__body["explain"] = explain
442-
if ext is not None:
443-
__body["ext"] = ext
444-
if fields is not None:
445-
__body["fields"] = fields
446467
if filter_path is not None:
447468
__query["filter_path"] = filter_path
448-
if from_ is not None:
449-
__body["from"] = from_
450-
if highlight is not None:
451-
__body["highlight"] = highlight
452469
if human is not None:
453470
__query["human"] = human
454471
if ignore_throttled is not None:
455472
__query["ignore_throttled"] = ignore_throttled
456473
if ignore_unavailable is not None:
457474
__query["ignore_unavailable"] = ignore_unavailable
458-
if indices_boost is not None:
459-
__body["indices_boost"] = indices_boost
460475
if keep_alive is not None:
461476
__query["keep_alive"] = keep_alive
462477
if keep_on_completion is not None:
463478
__query["keep_on_completion"] = keep_on_completion
464-
if knn is not None:
465-
__body["knn"] = knn
466479
if lenient is not None:
467480
__query["lenient"] = lenient
468481
if max_concurrent_shard_requests is not None:
469482
__query["max_concurrent_shard_requests"] = max_concurrent_shard_requests
470483
if min_compatible_shard_node is not None:
471484
__query["min_compatible_shard_node"] = min_compatible_shard_node
472-
if min_score is not None:
473-
__body["min_score"] = min_score
474-
if pit is not None:
475-
__body["pit"] = pit
476-
if post_filter is not None:
477-
__body["post_filter"] = post_filter
478485
if pre_filter_shard_size is not None:
479486
__query["pre_filter_shard_size"] = pre_filter_shard_size
480487
if preference is not None:
481488
__query["preference"] = preference
482489
if pretty is not None:
483490
__query["pretty"] = pretty
484-
if profile is not None:
485-
__body["profile"] = profile
486491
if q is not None:
487492
__query["q"] = q
488-
if query is not None:
489-
__body["query"] = query
490493
if request_cache is not None:
491494
__query["request_cache"] = request_cache
492-
if rescore is not None:
493-
__body["rescore"] = rescore
494495
if rest_total_hits_as_int is not None:
495496
__query["rest_total_hits_as_int"] = rest_total_hits_as_int
496497
if routing is not None:
497498
__query["routing"] = routing
498-
if runtime_mappings is not None:
499-
__body["runtime_mappings"] = runtime_mappings
500-
if script_fields is not None:
501-
__body["script_fields"] = script_fields
502499
if scroll is not None:
503500
__query["scroll"] = scroll
504-
if search_after is not None:
505-
__body["search_after"] = search_after
506501
if search_type is not None:
507502
__query["search_type"] = search_type
508-
if seq_no_primary_term is not None:
509-
__body["seq_no_primary_term"] = seq_no_primary_term
510-
if size is not None:
511-
__body["size"] = size
512-
if slice is not None:
513-
__body["slice"] = slice
514-
if sort is not None:
515-
__body["sort"] = sort
516-
if source is not None:
517-
__body["_source"] = source
518503
if source_excludes is not None:
519504
__query["_source_excludes"] = source_excludes
520505
if source_includes is not None:
521506
__query["_source_includes"] = source_includes
522-
if stats is not None:
523-
__body["stats"] = stats
524-
if stored_fields is not None:
525-
__body["stored_fields"] = stored_fields
526-
if suggest is not None:
527-
__body["suggest"] = suggest
528507
if suggest_field is not None:
529508
__query["suggest_field"] = suggest_field
530509
if suggest_mode is not None:
@@ -533,20 +512,77 @@ async def submit(
533512
__query["suggest_size"] = suggest_size
534513
if suggest_text is not None:
535514
__query["suggest_text"] = suggest_text
536-
if terminate_after is not None:
537-
__body["terminate_after"] = terminate_after
538-
if timeout is not None:
539-
__body["timeout"] = timeout
540-
if track_scores is not None:
541-
__body["track_scores"] = track_scores
542-
if track_total_hits is not None:
543-
__body["track_total_hits"] = track_total_hits
544515
if typed_keys is not None:
545516
__query["typed_keys"] = typed_keys
546-
if version is not None:
547-
__body["version"] = version
548517
if wait_for_completion_timeout is not None:
549518
__query["wait_for_completion_timeout"] = wait_for_completion_timeout
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)