Skip to content

Commit 772f21d

Browse files
committed
Add aliased parameters
1 parent 7c9ca83 commit 772f21d

File tree

12 files changed

+76
-7
lines changed

12 files changed

+76
-7
lines changed

elasticsearch/_async/client/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,6 +3069,7 @@ async def search(
30693069
*,
30703070
index: Optional[Any] = None,
30713071
aggregations: Optional[Dict[str, Any]] = None,
3072+
aggs: Optional[Dict[str, Any]] = None,
30723073
allow_no_indices: Optional[bool] = None,
30733074
allow_partial_search_results: Optional[bool] = None,
30743075
analyze_wildcard: Optional[bool] = None,
@@ -3140,6 +3141,7 @@ async def search(
31403141
:param index: A comma-separated list of index names to search; use `_all` or
31413142
empty string to perform the operation on all indices
31423143
:param aggregations:
3144+
:param aggs:
31433145
:param allow_no_indices: Whether to ignore if a wildcard indices expression resolves
31443146
into no concrete indices. (This includes `_all` string or when no indices
31453147
have been specified)
@@ -3266,6 +3268,8 @@ async def search(
32663268
__query: Dict[str, Any] = {}
32673269
if aggregations is not None:
32683270
__body["aggregations"] = aggregations
3271+
if aggs is not None:
3272+
__body["aggs"] = aggs
32693273
if allow_no_indices is not None:
32703274
__query["allow_no_indices"] = allow_no_indices
32713275
if allow_partial_search_results is not None:

elasticsearch/_async/client/async_search.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ async def submit(
162162
*,
163163
index: Optional[Any] = None,
164164
aggregations: Optional[Dict[str, Any]] = None,
165+
aggs: Optional[Dict[str, Any]] = None,
165166
allow_no_indices: Optional[bool] = None,
166167
allow_partial_search_results: Optional[bool] = None,
167168
analyze_wildcard: Optional[bool] = None,
@@ -236,6 +237,7 @@ async def submit(
236237
:param index: A comma-separated list of index names to search; use `_all` or
237238
empty string to perform the operation on all indices
238239
:param aggregations:
240+
:param aggs:
239241
:param allow_no_indices: Whether to ignore if a wildcard indices expression resolves
240242
into no concrete indices. (This includes `_all` string or when no indices
241243
have been specified)
@@ -359,6 +361,8 @@ async def submit(
359361
__query: Dict[str, Any] = {}
360362
if aggregations is not None:
361363
__body["aggregations"] = aggregations
364+
if aggs is not None:
365+
__body["aggs"] = aggs
362366
if allow_no_indices is not None:
363367
__query["allow_no_indices"] = allow_no_indices
364368
if allow_partial_search_results is not None:

elasticsearch/_async/client/ml.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,7 @@ async def put_datafeed(
26142614
human: Optional[bool] = None,
26152615
ignore_throttled: Optional[bool] = None,
26162616
ignore_unavailable: Optional[bool] = None,
2617+
indexes: Optional[List[str]] = None,
26172618
indices: Optional[List[str]] = None,
26182619
indices_options: Optional[Any] = None,
26192620
job_id: Optional[Any] = None,
@@ -2663,6 +2664,9 @@ async def put_datafeed(
26632664
:param ignore_throttled: Ignore indices that are marked as throttled (default:
26642665
true)
26652666
:param ignore_unavailable: Ignore unavailable indexes (default: false)
2667+
:param indexes: An array of index names. Wildcards are supported. If any of the
2668+
indices are in remote clusters, the machine learning nodes must have the
2669+
`remote_cluster_client` role.
26662670
:param indices: An array of index names. Wildcards are supported. If any of the
26672671
indices are in remote clusters, the machine learning nodes must have the
26682672
`remote_cluster_client` role.
@@ -2719,6 +2723,8 @@ async def put_datafeed(
27192723
__query["ignore_throttled"] = ignore_throttled
27202724
if ignore_unavailable is not None:
27212725
__query["ignore_unavailable"] = ignore_unavailable
2726+
if indexes is not None:
2727+
__body["indexes"] = indexes
27222728
if indices is not None:
27232729
__body["indices"] = indices
27242730
if indices_options is not None:

elasticsearch/_async/client/rollup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ async def rollup_search(
296296
index: Any,
297297
type: Optional[Any] = None,
298298
aggregations: Optional[Dict[str, Any]] = None,
299+
aggs: Optional[Dict[str, Any]] = None,
299300
error_trace: Optional[bool] = None,
300301
filter_path: Optional[Union[List[str], str]] = None,
301302
human: Optional[bool] = None,
@@ -314,6 +315,7 @@ async def rollup_search(
314315
that should be searched
315316
:param type: The doc type inside the index
316317
:param aggregations:
318+
:param aggs:
317319
:param query:
318320
:param rest_total_hits_as_int: Indicates whether hits.total should be rendered
319321
as an integer or an object in the rest search response
@@ -333,6 +335,8 @@ async def rollup_search(
333335
__query: Dict[str, Any] = {}
334336
if aggregations is not None:
335337
__body["aggregations"] = aggregations
338+
if aggs is not None:
339+
__body["aggs"] = aggs
336340
if error_trace is not None:
337341
__query["error_trace"] = error_trace
338342
if filter_path is not None:

elasticsearch/_sync/client/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,6 +3029,7 @@ def search(
30293029
*,
30303030
index: Optional[Any] = None,
30313031
aggregations: Optional[Dict[str, Any]] = None,
3032+
aggs: Optional[Dict[str, Any]] = None,
30323033
allow_no_indices: Optional[bool] = None,
30333034
allow_partial_search_results: Optional[bool] = None,
30343035
analyze_wildcard: Optional[bool] = None,
@@ -3100,6 +3101,7 @@ def search(
31003101
:param index: A comma-separated list of index names to search; use `_all` or
31013102
empty string to perform the operation on all indices
31023103
:param aggregations:
3104+
:param aggs:
31033105
:param allow_no_indices: Whether to ignore if a wildcard indices expression resolves
31043106
into no concrete indices. (This includes `_all` string or when no indices
31053107
have been specified)
@@ -3226,6 +3228,8 @@ def search(
32263228
__query: Dict[str, Any] = {}
32273229
if aggregations is not None:
32283230
__body["aggregations"] = aggregations
3231+
if aggs is not None:
3232+
__body["aggs"] = aggs
32293233
if allow_no_indices is not None:
32303234
__query["allow_no_indices"] = allow_no_indices
32313235
if allow_partial_search_results is not None:

elasticsearch/_sync/client/async_search.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def submit(
162162
*,
163163
index: Optional[Any] = None,
164164
aggregations: Optional[Dict[str, Any]] = None,
165+
aggs: Optional[Dict[str, Any]] = None,
165166
allow_no_indices: Optional[bool] = None,
166167
allow_partial_search_results: Optional[bool] = None,
167168
analyze_wildcard: Optional[bool] = None,
@@ -236,6 +237,7 @@ def submit(
236237
:param index: A comma-separated list of index names to search; use `_all` or
237238
empty string to perform the operation on all indices
238239
:param aggregations:
240+
:param aggs:
239241
:param allow_no_indices: Whether to ignore if a wildcard indices expression resolves
240242
into no concrete indices. (This includes `_all` string or when no indices
241243
have been specified)
@@ -359,6 +361,8 @@ def submit(
359361
__query: Dict[str, Any] = {}
360362
if aggregations is not None:
361363
__body["aggregations"] = aggregations
364+
if aggs is not None:
365+
__body["aggs"] = aggs
362366
if allow_no_indices is not None:
363367
__query["allow_no_indices"] = allow_no_indices
364368
if allow_partial_search_results is not None:

elasticsearch/_sync/client/ml.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,6 +2576,7 @@ def put_datafeed(
25762576
human: Optional[bool] = None,
25772577
ignore_throttled: Optional[bool] = None,
25782578
ignore_unavailable: Optional[bool] = None,
2579+
indexes: Optional[List[str]] = None,
25792580
indices: Optional[List[str]] = None,
25802581
indices_options: Optional[Any] = None,
25812582
job_id: Optional[Any] = None,
@@ -2625,6 +2626,9 @@ def put_datafeed(
26252626
:param ignore_throttled: Ignore indices that are marked as throttled (default:
26262627
true)
26272628
:param ignore_unavailable: Ignore unavailable indexes (default: false)
2629+
:param indexes: An array of index names. Wildcards are supported. If any of the
2630+
indices are in remote clusters, the machine learning nodes must have the
2631+
`remote_cluster_client` role.
26282632
:param indices: An array of index names. Wildcards are supported. If any of the
26292633
indices are in remote clusters, the machine learning nodes must have the
26302634
`remote_cluster_client` role.
@@ -2681,6 +2685,8 @@ def put_datafeed(
26812685
__query["ignore_throttled"] = ignore_throttled
26822686
if ignore_unavailable is not None:
26832687
__query["ignore_unavailable"] = ignore_unavailable
2688+
if indexes is not None:
2689+
__body["indexes"] = indexes
26842690
if indices is not None:
26852691
__body["indices"] = indices
26862692
if indices_options is not None:

elasticsearch/_sync/client/rollup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def rollup_search(
292292
index: Any,
293293
type: Optional[Any] = None,
294294
aggregations: Optional[Dict[str, Any]] = None,
295+
aggs: Optional[Dict[str, Any]] = None,
295296
error_trace: Optional[bool] = None,
296297
filter_path: Optional[Union[List[str], str]] = None,
297298
human: Optional[bool] = None,
@@ -310,6 +311,7 @@ def rollup_search(
310311
that should be searched
311312
:param type: The doc type inside the index
312313
:param aggregations:
314+
:param aggs:
313315
:param query:
314316
:param rest_total_hits_as_int: Indicates whether hits.total should be rendered
315317
as an integer or an object in the rest search response
@@ -329,6 +331,8 @@ def rollup_search(
329331
__query: Dict[str, Any] = {}
330332
if aggregations is not None:
331333
__body["aggregations"] = aggregations
334+
if aggs is not None:
335+
__body["aggs"] = aggs
332336
if error_trace is not None:
333337
__query["error_trace"] = error_trace
334338
if filter_path is not None:

elasticsearch/_sync/client/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def _quote(value: Any) -> str:
237237

238238

239239
def _quote_query(query: Dict[str, Any]) -> str:
240-
return "&".join([f"{k}={percent_encode(_escape(v), ',*')}" for k, v in query.items()])
240+
return "&".join([f"{k}={_quote(v)}" for k, v in query.items()])
241241

242242

243243
def _merge_kwargs_no_duplicates(kwargs: Dict[str, Any], values: Dict[str, Any]) -> None:

test_elasticsearch/test_async/test_server/test_rest_api_spec.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
clients.
2222
"""
2323
import inspect
24+
import json
2425
import warnings
2526

2627
import pytest
@@ -30,6 +31,7 @@
3031
from ...test_server.test_rest_api_spec import (
3132
IMPLEMENTED_FEATURES,
3233
PARAMS_RENAMES,
34+
API_PARAMS_RENAMES,
3335
RUN_ASYNC_REST_API_TESTS,
3436
YAML_TEST_SPECS,
3537
YamlRunner,
@@ -134,11 +136,20 @@ async def run_do(self, action):
134136
assert hasattr(api, m)
135137
api = getattr(api, m)
136138

139+
# Sometimes the 'body' parameter is encoded as a string instead of raw.
140+
if "body" in args:
141+
try:
142+
args["body"] = json.loads(args["body"])
143+
except (TypeError, ValueError):
144+
pass
145+
137146
# some parameters had to be renamed to not clash with python builtins,
138147
# compensate
139-
for k in PARAMS_RENAMES:
148+
renames = PARAMS_RENAMES.copy()
149+
renames.update(API_PARAMS_RENAMES.get(method, {}))
150+
for k in renames:
140151
if k in args:
141-
args[PARAMS_RENAMES[k]] = args.pop(k)
152+
args[renames[k]] = args.pop(k)
142153

143154
# resolve vars
144155
for k in args:

test_elasticsearch/test_client/test_indices.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ def test_passing_empty_value_for_required_param_raises_exception(self):
4242
self.client.indices.exists(index="")
4343

4444
def test_query_params(self):
45-
self.client.indices.delete(index=["test1", "test*"], expand_wildcards=["open", "closed"])
45+
self.client.indices.delete(
46+
index=["test1", "test*"], expand_wildcards=["open", "closed"]
47+
)
4648
self.assert_url_called("DELETE", "/test1,test*?expand_wildcards=open,closed")

test_elasticsearch/test_server/test_rest_api_spec.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141
# some params had to be changed in python, keep track of them so we can rename
4242
# those in the tests accordingly
4343
PARAMS_RENAMES = {"type": "doc_type", "from": "from_"}
44+
API_PARAMS_RENAMES = {
45+
"snapshot.create_repository": {"repository": "name"},
46+
"snapshot.delete_repository": {"repository": "name"},
47+
"snapshot.get_repository": {"repository": "name"},
48+
"snapshot.cleanup_repository": {"repository": "name"},
49+
"snapshot.verify_repository": {"repository": "name"},
50+
"ilm.delete_lifecycle": {"policy", "name"},
51+
"ilm.get_lifecycle": {"policy": "name"},
52+
"ilm.put_lifecycle": {"policy": "name"},
53+
}
4454

4555
# mapping from catch values to http status codes
4656
CATCH_CODES = {"missing": 404, "conflict": 409, "unauthorized": 401}
@@ -228,11 +238,20 @@ def run_do(self, action):
228238
assert hasattr(api, m)
229239
api = getattr(api, m)
230240

241+
# Sometimes the 'body' parameter is encoded as a string instead of raw.
242+
if "body" in args:
243+
try:
244+
args["body"] = json.loads(args["body"])
245+
except (TypeError, ValueError):
246+
pass
247+
231248
# some parameters had to be renamed to not clash with python builtins,
232249
# compensate
233-
for k in PARAMS_RENAMES:
250+
renames = PARAMS_RENAMES.copy()
251+
renames.update(API_PARAMS_RENAMES.get(method, {}))
252+
for k in renames:
234253
if k in args:
235-
args[PARAMS_RENAMES[k]] = args.pop(k)
254+
args[renames[k]] = args.pop(k)
236255

237256
# resolve vars
238257
for k in args:
@@ -269,8 +288,9 @@ def run_do(self, action):
269288
)
270289

271290
def run_catch(self, catch, exception):
272-
if catch == "param":
291+
if catch == "param" or isinstance(exception, TypeError):
273292
assert isinstance(exception, TypeError)
293+
self.last_response = None
274294
return
275295

276296
assert isinstance(exception, ApiError)

0 commit comments

Comments
 (0)