Skip to content

Commit 300e738

Browse files
authored
Allow unrestricted body again (#34)
1 parent 34deed5 commit 300e738

38 files changed

+3494
-2340
lines changed

elasticsearch_serverless/_async/client/__init__.py

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

elasticsearch_serverless/_async/client/async_search.py

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

158158
@_rewrite_parameters(
159-
body_fields=True,
159+
body_fields=(
160+
"aggregations",
161+
"aggs",
162+
"collapse",
163+
"docvalue_fields",
164+
"explain",
165+
"ext",
166+
"fields",
167+
"from_",
168+
"highlight",
169+
"indices_boost",
170+
"knn",
171+
"min_score",
172+
"pit",
173+
"post_filter",
174+
"profile",
175+
"query",
176+
"rescore",
177+
"runtime_mappings",
178+
"script_fields",
179+
"search_after",
180+
"seq_no_primary_term",
181+
"size",
182+
"slice",
183+
"sort",
184+
"source",
185+
"stats",
186+
"stored_fields",
187+
"suggest",
188+
"terminate_after",
189+
"timeout",
190+
"track_scores",
191+
"track_total_hits",
192+
"version",
193+
),
160194
parameter_aliases={
161195
"_source": "source",
162196
"_source_excludes": "source_excludes",
@@ -261,6 +295,7 @@ async def submit(
261295
wait_for_completion_timeout: t.Optional[
262296
t.Union["t.Literal[-1]", "t.Literal[0]", str]
263297
] = None,
298+
body: t.Optional[t.Dict[str, t.Any]] = None,
264299
) -> ObjectApiResponse[t.Any]:
265300
"""
266301
Executes a search request asynchronously.
@@ -397,8 +432,8 @@ async def submit(
397432
__path = f"/{_quote(index)}/_async_search"
398433
else:
399434
__path = "/_async_search"
400-
__body: t.Dict[str, t.Any] = {}
401435
__query: t.Dict[str, t.Any] = {}
436+
__body: t.Dict[str, t.Any] = body if body is not None else {}
402437
# The 'sort' parameter with a colon can't be encoded to the body.
403438
if sort is not None and (
404439
(isinstance(sort, str) and ":" in sort)
@@ -410,10 +445,6 @@ async def submit(
410445
):
411446
__query["sort"] = sort
412447
sort = None
413-
if aggregations is not None:
414-
__body["aggregations"] = aggregations
415-
if aggs is not None:
416-
__body["aggs"] = aggs
417448
if allow_no_indices is not None:
418449
__query["allow_no_indices"] = allow_no_indices
419450
if allow_partial_search_results is not None:
@@ -426,106 +457,54 @@ async def submit(
426457
__query["batched_reduce_size"] = batched_reduce_size
427458
if ccs_minimize_roundtrips is not None:
428459
__query["ccs_minimize_roundtrips"] = ccs_minimize_roundtrips
429-
if collapse is not None:
430-
__body["collapse"] = collapse
431460
if default_operator is not None:
432461
__query["default_operator"] = default_operator
433462
if df is not None:
434463
__query["df"] = df
435-
if docvalue_fields is not None:
436-
__body["docvalue_fields"] = docvalue_fields
437464
if error_trace is not None:
438465
__query["error_trace"] = error_trace
439466
if expand_wildcards is not None:
440467
__query["expand_wildcards"] = expand_wildcards
441-
if explain is not None:
442-
__body["explain"] = explain
443-
if ext is not None:
444-
__body["ext"] = ext
445-
if fields is not None:
446-
__body["fields"] = fields
447468
if filter_path is not None:
448469
__query["filter_path"] = filter_path
449-
if from_ is not None:
450-
__body["from"] = from_
451-
if highlight is not None:
452-
__body["highlight"] = highlight
453470
if human is not None:
454471
__query["human"] = human
455472
if ignore_throttled is not None:
456473
__query["ignore_throttled"] = ignore_throttled
457474
if ignore_unavailable is not None:
458475
__query["ignore_unavailable"] = ignore_unavailable
459-
if indices_boost is not None:
460-
__body["indices_boost"] = indices_boost
461476
if keep_alive is not None:
462477
__query["keep_alive"] = keep_alive
463478
if keep_on_completion is not None:
464479
__query["keep_on_completion"] = keep_on_completion
465-
if knn is not None:
466-
__body["knn"] = knn
467480
if lenient is not None:
468481
__query["lenient"] = lenient
469482
if max_concurrent_shard_requests is not None:
470483
__query["max_concurrent_shard_requests"] = max_concurrent_shard_requests
471484
if min_compatible_shard_node is not None:
472485
__query["min_compatible_shard_node"] = min_compatible_shard_node
473-
if min_score is not None:
474-
__body["min_score"] = min_score
475-
if pit is not None:
476-
__body["pit"] = pit
477-
if post_filter is not None:
478-
__body["post_filter"] = post_filter
479486
if pre_filter_shard_size is not None:
480487
__query["pre_filter_shard_size"] = pre_filter_shard_size
481488
if preference is not None:
482489
__query["preference"] = preference
483490
if pretty is not None:
484491
__query["pretty"] = pretty
485-
if profile is not None:
486-
__body["profile"] = profile
487492
if q is not None:
488493
__query["q"] = q
489-
if query is not None:
490-
__body["query"] = query
491494
if request_cache is not None:
492495
__query["request_cache"] = request_cache
493-
if rescore is not None:
494-
__body["rescore"] = rescore
495496
if rest_total_hits_as_int is not None:
496497
__query["rest_total_hits_as_int"] = rest_total_hits_as_int
497498
if routing is not None:
498499
__query["routing"] = routing
499-
if runtime_mappings is not None:
500-
__body["runtime_mappings"] = runtime_mappings
501-
if script_fields is not None:
502-
__body["script_fields"] = script_fields
503500
if scroll is not None:
504501
__query["scroll"] = scroll
505-
if search_after is not None:
506-
__body["search_after"] = search_after
507502
if search_type is not None:
508503
__query["search_type"] = search_type
509-
if seq_no_primary_term is not None:
510-
__body["seq_no_primary_term"] = seq_no_primary_term
511-
if size is not None:
512-
__body["size"] = size
513-
if slice is not None:
514-
__body["slice"] = slice
515-
if sort is not None:
516-
__body["sort"] = sort
517-
if source is not None:
518-
__body["_source"] = source
519504
if source_excludes is not None:
520505
__query["_source_excludes"] = source_excludes
521506
if source_includes is not None:
522507
__query["_source_includes"] = source_includes
523-
if stats is not None:
524-
__body["stats"] = stats
525-
if stored_fields is not None:
526-
__body["stored_fields"] = stored_fields
527-
if suggest is not None:
528-
__body["suggest"] = suggest
529508
if suggest_field is not None:
530509
__query["suggest_field"] = suggest_field
531510
if suggest_mode is not None:
@@ -534,20 +513,77 @@ async def submit(
534513
__query["suggest_size"] = suggest_size
535514
if suggest_text is not None:
536515
__query["suggest_text"] = suggest_text
537-
if terminate_after is not None:
538-
__body["terminate_after"] = terminate_after
539-
if timeout is not None:
540-
__body["timeout"] = timeout
541-
if track_scores is not None:
542-
__body["track_scores"] = track_scores
543-
if track_total_hits is not None:
544-
__body["track_total_hits"] = track_total_hits
545516
if typed_keys is not None:
546517
__query["typed_keys"] = typed_keys
547-
if version is not None:
548-
__body["version"] = version
549518
if wait_for_completion_timeout is not None:
550519
__query["wait_for_completion_timeout"] = wait_for_completion_timeout
520+
if not __body:
521+
if aggregations is not None:
522+
__body["aggregations"] = aggregations
523+
if aggs is not None:
524+
__body["aggs"] = aggs
525+
if collapse is not None:
526+
__body["collapse"] = collapse
527+
if docvalue_fields is not None:
528+
__body["docvalue_fields"] = docvalue_fields
529+
if explain is not None:
530+
__body["explain"] = explain
531+
if ext is not None:
532+
__body["ext"] = ext
533+
if fields is not None:
534+
__body["fields"] = fields
535+
if from_ is not None:
536+
__body["from"] = from_
537+
if highlight is not None:
538+
__body["highlight"] = highlight
539+
if indices_boost is not None:
540+
__body["indices_boost"] = indices_boost
541+
if knn is not None:
542+
__body["knn"] = knn
543+
if min_score is not None:
544+
__body["min_score"] = min_score
545+
if pit is not None:
546+
__body["pit"] = pit
547+
if post_filter is not None:
548+
__body["post_filter"] = post_filter
549+
if profile is not None:
550+
__body["profile"] = profile
551+
if query is not None:
552+
__body["query"] = query
553+
if rescore is not None:
554+
__body["rescore"] = rescore
555+
if runtime_mappings is not None:
556+
__body["runtime_mappings"] = runtime_mappings
557+
if script_fields is not None:
558+
__body["script_fields"] = script_fields
559+
if search_after is not None:
560+
__body["search_after"] = search_after
561+
if seq_no_primary_term is not None:
562+
__body["seq_no_primary_term"] = seq_no_primary_term
563+
if size is not None:
564+
__body["size"] = size
565+
if slice is not None:
566+
__body["slice"] = slice
567+
if sort is not None:
568+
__body["sort"] = sort
569+
if source is not None:
570+
__body["_source"] = source
571+
if stats is not None:
572+
__body["stats"] = stats
573+
if stored_fields is not None:
574+
__body["stored_fields"] = stored_fields
575+
if suggest is not None:
576+
__body["suggest"] = suggest
577+
if terminate_after is not None:
578+
__body["terminate_after"] = terminate_after
579+
if timeout is not None:
580+
__body["timeout"] = timeout
581+
if track_scores is not None:
582+
__body["track_scores"] = track_scores
583+
if track_total_hits is not None:
584+
__body["track_total_hits"] = track_total_hits
585+
if version is not None:
586+
__body["version"] = version
551587
if not __body:
552588
__body = None # type: ignore[assignment]
553589
__headers = {"accept": "application/json"}

elasticsearch_serverless/_async/client/cluster.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,14 @@ async def info(
225225
)
226226

227227
@_rewrite_parameters(
228-
body_fields=True,
228+
body_fields=("template", "allow_auto_create", "meta", "version"),
229229
parameter_aliases={"_meta": "meta"},
230230
)
231231
async def put_component_template(
232232
self,
233233
*,
234234
name: str,
235-
template: t.Mapping[str, t.Any],
235+
template: t.Optional[t.Mapping[str, t.Any]] = None,
236236
allow_auto_create: t.Optional[bool] = None,
237237
create: t.Optional[bool] = None,
238238
error_trace: t.Optional[bool] = None,
@@ -244,6 +244,7 @@ async def put_component_template(
244244
meta: t.Optional[t.Mapping[str, t.Any]] = None,
245245
pretty: t.Optional[bool] = None,
246246
version: t.Optional[int] = None,
247+
body: t.Optional[t.Dict[str, t.Any]] = None,
247248
) -> ObjectApiResponse[t.Any]:
248249
"""
249250
Creates or updates a component template
@@ -281,15 +282,11 @@ async def put_component_template(
281282
"""
282283
if name in SKIP_IN_PATH:
283284
raise ValueError("Empty value passed for parameter 'name'")
284-
if template is None:
285+
if template is None and body is None:
285286
raise ValueError("Empty value passed for parameter 'template'")
286287
__path = f"/_component_template/{_quote(name)}"
287-
__body: t.Dict[str, t.Any] = {}
288288
__query: t.Dict[str, t.Any] = {}
289-
if template is not None:
290-
__body["template"] = template
291-
if allow_auto_create is not None:
292-
__body["allow_auto_create"] = allow_auto_create
289+
__body: t.Dict[str, t.Any] = body if body is not None else {}
293290
if create is not None:
294291
__query["create"] = create
295292
if error_trace is not None:
@@ -300,12 +297,17 @@ async def put_component_template(
300297
__query["human"] = human
301298
if master_timeout is not None:
302299
__query["master_timeout"] = master_timeout
303-
if meta is not None:
304-
__body["_meta"] = meta
305300
if pretty is not None:
306301
__query["pretty"] = pretty
307-
if version is not None:
308-
__body["version"] = version
302+
if not __body:
303+
if template is not None:
304+
__body["template"] = template
305+
if allow_auto_create is not None:
306+
__body["allow_auto_create"] = allow_auto_create
307+
if meta is not None:
308+
__body["_meta"] = meta
309+
if version is not None:
310+
__body["version"] = version
309311
__headers = {"accept": "application/json", "content-type": "application/json"}
310312
return await self.perform_request( # type: ignore[return-value]
311313
"PUT", __path, params=__query, headers=__headers, body=__body

elasticsearch_serverless/_async/client/enrich.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async def get_policy(
135135
)
136136

137137
@_rewrite_parameters(
138-
body_fields=True,
138+
body_fields=("geo_match", "match", "range"),
139139
)
140140
async def put_policy(
141141
self,
@@ -148,6 +148,7 @@ async def put_policy(
148148
match: t.Optional[t.Mapping[str, t.Any]] = None,
149149
pretty: t.Optional[bool] = None,
150150
range: t.Optional[t.Mapping[str, t.Any]] = None,
151+
body: t.Optional[t.Dict[str, t.Any]] = None,
151152
) -> ObjectApiResponse[t.Any]:
152153
"""
153154
Creates a new enrich policy.
@@ -165,21 +166,22 @@ async def put_policy(
165166
raise ValueError("Empty value passed for parameter 'name'")
166167
__path = f"/_enrich/policy/{_quote(name)}"
167168
__query: t.Dict[str, t.Any] = {}
168-
__body: t.Dict[str, t.Any] = {}
169+
__body: t.Dict[str, t.Any] = body if body is not None else {}
169170
if error_trace is not None:
170171
__query["error_trace"] = error_trace
171172
if filter_path is not None:
172173
__query["filter_path"] = filter_path
173-
if geo_match is not None:
174-
__body["geo_match"] = geo_match
175174
if human is not None:
176175
__query["human"] = human
177-
if match is not None:
178-
__body["match"] = match
179176
if pretty is not None:
180177
__query["pretty"] = pretty
181-
if range is not None:
182-
__body["range"] = range
178+
if not __body:
179+
if geo_match is not None:
180+
__body["geo_match"] = geo_match
181+
if match is not None:
182+
__body["match"] = match
183+
if range is not None:
184+
__body["range"] = range
183185
__headers = {"accept": "application/json", "content-type": "application/json"}
184186
return await self.perform_request( # type: ignore[return-value]
185187
"PUT", __path, params=__query, headers=__headers, body=__body

0 commit comments

Comments
 (0)