Skip to content

Commit cd24521

Browse files
committed
Add aliased parameters
1 parent 7c9ca83 commit cd24521

File tree

19 files changed

+129
-42
lines changed

19 files changed

+129
-42
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/_async/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def _process_bulk_chunk(
6666

6767
try:
6868
# send the actual request
69-
resp = await client.bulk(*args, body=bulk_actions, **kwargs)
69+
resp = await client.bulk(*args, operations=bulk_actions, **kwargs)
7070
except TransportError as e:
7171
gen = _process_bulk_chunk_error(
7272
error=e,

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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"request_timeout",
7272
"opaque_id",
7373
"headers",
74+
"ignore",
7475
}
7576

7677
RT = TypeVar("RT")
@@ -237,7 +238,7 @@ def _quote(value: Any) -> str:
237238

238239

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

242243

243244
def _merge_kwargs_no_duplicates(kwargs: Dict[str, Any], values: Dict[str, Any]) -> None:
@@ -287,7 +288,10 @@ def wrapped(*args: Any, **kwargs: Any) -> RT:
287288
if option in options_to_skip:
288289
continue
289290
try:
290-
transport_options[option] = kwargs.pop(option)
291+
option_rename = option
292+
if option == "ignore":
293+
option_rename = "ignore_status"
294+
transport_options[option_rename] = kwargs.pop(option)
291295
except KeyError:
292296
pass
293297
if transport_options:

elasticsearch/helpers/actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def _process_bulk_chunk(
237237

238238
try:
239239
# send the actual request
240-
resp = client.bulk(*args, body=bulk_actions, **kwargs)
240+
resp = client.bulk(*args, operations=bulk_actions, **kwargs)
241241
except TransportError as e:
242242
gen = _process_bulk_chunk_error(
243243
error=e,

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ignore = E203, E266, E501, W503
66

77
[tool:pytest]
88
junit_family=legacy
9-
addopts = -vvv --cov-report=term-missing --cov=elasticsearch --cov-config=.coveragerc
9+
addopts = -vvv -p no:logging --cov-report=term-missing --cov=elasticsearch --cov-config=.coveragerc
1010

1111
[tool:isort]
1212
profile=black

test_elasticsearch/test_async/test_server/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def async_client(elasticsearch_url):
3838
client = None
3939
try:
4040
client = elasticsearch.AsyncElasticsearch(
41-
elasticsearch_url, timeout=3, ca_certs=CA_CERTS
41+
elasticsearch_url, request_timeout=3, ca_certs=CA_CERTS
4242
)
4343
yield client
4444
finally:

test_elasticsearch/test_async/test_server/test_clients.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,35 @@
2323
pytestmark = pytest.mark.asyncio
2424

2525

26-
class TestUnicode:
27-
async def test_indices_analyze(self, async_client):
28-
await async_client.indices.analyze(body='{"text": "привет"}')
29-
30-
31-
class TestBulk:
32-
async def test_bulk_works_with_string_body(self, async_client):
33-
docs = '{ "index" : { "_index" : "bulk_test_index", "_id" : "1" } }\n{"answer": 42}'
34-
response = await async_client.bulk(body=docs)
35-
36-
assert response["errors"] is False
37-
assert len(response["items"]) == 1
38-
39-
async def test_bulk_works_with_bytestring_body(self, async_client):
40-
docs = b'{ "index" : { "_index" : "bulk_test_index", "_id" : "2" } }\n{"answer": 42}'
41-
response = await async_client.bulk(body=docs)
42-
43-
assert response["errors"] is False
44-
assert len(response["items"]) == 1
26+
@pytest.mark.parametrize("kwargs", [{"body": {"text": "привет"}}, {"text": "привет"}])
27+
async def test_indices_analyze_unicode(async_client, kwargs):
28+
resp = await async_client.indices.analyze(**kwargs)
29+
assert resp == {
30+
"tokens": [
31+
{
32+
"end_offset": 6,
33+
"position": 0,
34+
"start_offset": 0,
35+
"token": "привет",
36+
"type": "<ALPHANUM>",
37+
}
38+
]
39+
}
40+
41+
42+
async def test_bulk_works_with_string_body(self, async_client):
43+
docs = '{ "index" : { "_index" : "bulk_test_index", "_id" : "1" } }\n{"answer": 42}'
44+
response = await async_client.bulk(body=docs)
45+
46+
assert response["errors"] is False
47+
assert len(response["items"]) == 1
48+
49+
50+
async def test_bulk_works_with_bytestring_body(self, async_client):
51+
docs = (
52+
b'{ "index" : { "_index" : "bulk_test_index", "_id" : "2" } }\n{"answer": 42}'
53+
)
54+
response = await async_client.bulk(body=docs)
55+
56+
assert response["errors"] is False
57+
assert len(response["items"]) == 1

test_elasticsearch/test_async/test_server/test_helpers.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ async def test_order_can_be_preserved(self, async_client, scan_teardown):
476476
for x in range(100):
477477
bulk.append({"index": {"_index": "test_index", "_id": x}})
478478
bulk.append({"answer": x, "correct": x == 42})
479-
await async_client.bulk(bulk, refresh=True)
479+
await async_client.bulk(operations=bulk, refresh=True)
480480

481481
docs = [
482482
doc
@@ -497,7 +497,7 @@ async def test_all_documents_are_read(self, async_client, scan_teardown):
497497
for x in range(100):
498498
bulk.append({"index": {"_index": "test_index", "_id": x}})
499499
bulk.append({"answer": x, "correct": x == 42})
500-
await async_client.bulk(bulk, refresh=True)
500+
await async_client.bulk(operations=bulk, refresh=True)
501501

502502
docs = [
503503
x
@@ -513,7 +513,7 @@ async def test_scroll_error(self, async_client, scan_teardown):
513513
for x in range(4):
514514
bulk.append({"index": {"_index": "test_index"}})
515515
bulk.append({"value": x})
516-
await async_client.bulk(bulk, refresh=True)
516+
await async_client.bulk(operations=bulk, refresh=True)
517517

518518
with patch.object(
519519
async_client, "options", return_value=async_client
@@ -632,7 +632,7 @@ async def test_logger(self, logger_mock, async_client, scan_teardown):
632632
for x in range(4):
633633
bulk.append({"index": {"_index": "test_index"}})
634634
bulk.append({"value": x})
635-
await async_client.bulk(bulk, refresh=True)
635+
await async_client.bulk(operations=bulk, refresh=True)
636636

637637
with patch.object(
638638
async_client, "options", return_value=async_client
@@ -677,7 +677,7 @@ async def test_clear_scroll(self, async_client, scan_teardown):
677677
for x in range(4):
678678
bulk.append({"index": {"_index": "test_index"}})
679679
bulk.append({"value": x})
680-
await async_client.bulk(bulk, refresh=True)
680+
await async_client.bulk(operations=bulk, refresh=True)
681681

682682
with patch.object(
683683
async_client, "options", return_value=async_client
@@ -851,7 +851,7 @@ async def reindex_setup(async_client):
851851
"type": "answers" if x % 2 == 0 else "questions",
852852
}
853853
)
854-
await async_client.bulk(bulk, refresh=True)
854+
await async_client.bulk(operations=bulk, refresh=True)
855855
yield
856856

857857

@@ -992,7 +992,7 @@ async def reindex_data_stream_setup(async_client):
992992
"@timestamp": (dt - timedelta(days=x)).isoformat(),
993993
}
994994
)
995-
await async_client.bulk(bulk, refresh=True)
995+
await async_client.bulk(operations=bulk, refresh=True)
996996
await async_client.indices.put_index_template(
997997
name="my-index-template",
998998
body={

0 commit comments

Comments
 (0)