Skip to content

Commit 242adb0

Browse files
authored
Add Index v2 and Voting Config APIs
1 parent 04fee08 commit 242adb0

File tree

9 files changed

+88
-34
lines changed

9 files changed

+88
-34
lines changed

elasticsearch/client/__init__.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ def info(self, params=None, headers=None):
302302

303303
@query_params(
304304
"pipeline",
305-
"prefer_v2_templates",
306305
"refresh",
307306
"routing",
308307
"timeout",
@@ -322,8 +321,6 @@ def create(self, index, id, body, doc_type=None, params=None, headers=None):
322321
:arg doc_type: The type of the document
323322
:arg pipeline: The pipeline id to preprocess incoming documents
324323
with
325-
:arg prefer_v2_templates: favor V2 templates instead of V1
326-
templates during automatic index creation
327324
:arg refresh: If `true` then refresh the affected shards to make
328325
this operation visible to search, if `wait_for` then wait for a refresh
329326
to make this operation visible to search, if `false` (the default) then
@@ -361,7 +358,6 @@ def create(self, index, id, body, doc_type=None, params=None, headers=None):
361358
"if_seq_no",
362359
"op_type",
363360
"pipeline",
364-
"prefer_v2_templates",
365361
"refresh",
366362
"routing",
367363
"timeout",
@@ -388,8 +384,6 @@ def index(self, index, body, id=None, params=None, headers=None):
388384
without an explicit document ID Valid choices: index, create
389385
:arg pipeline: The pipeline id to preprocess incoming documents
390386
with
391-
:arg prefer_v2_templates: favor V2 templates instead of V1
392-
templates during automatic index creation
393387
:arg refresh: If `true` then refresh the affected shards to make
394388
this operation visible to search, if `wait_for` then wait for a refresh
395389
to make this operation visible to search, if `false` (the default) then
@@ -422,7 +416,6 @@ def index(self, index, body, id=None, params=None, headers=None):
422416
"_source_excludes",
423417
"_source_includes",
424418
"pipeline",
425-
"prefer_v2_templates",
426419
"refresh",
427420
"routing",
428421
"timeout",
@@ -447,8 +440,6 @@ def bulk(self, body, index=None, doc_type=None, params=None, headers=None):
447440
return from the _source field, can be overridden on each sub-request
448441
:arg pipeline: The pipeline id to preprocess incoming documents
449442
with
450-
:arg prefer_v2_templates: favor V2 templates instead of V1
451-
templates during automatic index creation
452443
:arg refresh: If `true` then refresh the affected shards to make
453444
this operation visible to search, if `wait_for` then wait for a refresh
454445
to make this operation visible to search, if `false` (the default) then
@@ -1533,7 +1524,6 @@ def search_shards(self, index=None, params=None, headers=None):
15331524
"if_primary_term",
15341525
"if_seq_no",
15351526
"lang",
1536-
"prefer_v2_templates",
15371527
"refresh",
15381528
"retry_on_conflict",
15391529
"routing",
@@ -1563,8 +1553,6 @@ def update(self, index, id, body, doc_type=None, params=None, headers=None):
15631553
operation that has changed the document has the specified sequence
15641554
number
15651555
:arg lang: The script language (default: painless)
1566-
:arg prefer_v2_templates: favor V2 templates instead of V1
1567-
templates during automatic index creation
15681556
:arg refresh: If `true` then refresh the affected shards to make
15691557
this operation visible to search, if `wait_for` then wait for a refresh
15701558
to make this operation visible to search, if `false` (the default) then

elasticsearch/client/autoscaling.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def get_autoscaling_decision(self, params=None, headers=None):
2020
@query_params()
2121
def delete_autoscaling_policy(self, name, params=None, headers=None):
2222
"""
23+
Deletes an autoscaling policy.
2324
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/autoscaling-delete-autoscaling-policy.html>`_
2425
2526
:arg name: the name of the autoscaling policy
@@ -37,6 +38,7 @@ def delete_autoscaling_policy(self, name, params=None, headers=None):
3738
@query_params()
3839
def put_autoscaling_policy(self, name, body, params=None, headers=None):
3940
"""
41+
Creates a new autoscaling policy.
4042
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/autoscaling-put-autoscaling-policy.html>`_
4143
4244
:arg name: the name of the autoscaling policy
@@ -57,6 +59,7 @@ def put_autoscaling_policy(self, name, body, params=None, headers=None):
5759
@query_params()
5860
def get_autoscaling_policy(self, name, params=None, headers=None):
5961
"""
62+
Retrieves an autoscaling policy.
6063
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/autoscaling-get-autoscaling-policy.html>`_
6164
6265
:arg name: the name of the autoscaling policy

elasticsearch/client/cat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def pending_tasks(self, params=None, headers=None):
326326
"GET", "/_cat/pending_tasks", params=params, headers=headers
327327
)
328328

329-
@query_params("format", "h", "help", "local", "master_timeout", "s", "size", "v")
329+
@query_params("format", "h", "help", "local", "master_timeout", "s", "time", "v")
330330
def thread_pool(self, thread_pool_patterns=None, params=None, headers=None):
331331
"""
332332
Returns cluster-wide thread pool statistics per node. By default the active,
@@ -345,8 +345,8 @@ def thread_pool(self, thread_pool_patterns=None, params=None, headers=None):
345345
to master node
346346
:arg s: Comma-separated list of column names or column aliases
347347
to sort by
348-
:arg size: The multiplier in which to display values Valid
349-
choices: , k, m, g, t, p
348+
:arg time: The unit in which to display time values Valid
349+
choices: d, h, m, s, ms, micros, nanos
350350
:arg v: Verbose mode. Display column headers
351351
"""
352352
return self.transport.perform_request(

elasticsearch/client/cluster.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,38 @@ def exists_component_template(self, name, params=None, headers=None):
324324
params=params,
325325
headers=headers,
326326
)
327+
328+
@query_params("wait_for_removal")
329+
def delete_voting_config_exclusions(self, params=None, headers=None):
330+
"""
331+
Clears cluster voting config exclusions.
332+
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html>`_
333+
334+
:arg wait_for_removal: Specifies whether to wait for all
335+
excluded nodes to be removed from the cluster before clearing the voting
336+
configuration exclusions list. Default: True
337+
"""
338+
return self.transport.perform_request(
339+
"DELETE",
340+
"/_cluster/voting_config_exclusions",
341+
params=params,
342+
headers=headers,
343+
)
344+
345+
@query_params("node_ids", "node_names", "timeout")
346+
def post_voting_config_exclusions(self, params=None, headers=None):
347+
"""
348+
Updates the cluster voting config exclusions by node ids or node names.
349+
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html>`_
350+
351+
:arg node_ids: A comma-separated list of the persistent ids of
352+
the nodes to exclude from the voting configuration. If specified, you
353+
may not also specify ?node_names.
354+
:arg node_names: A comma-separated list of the names of the
355+
nodes to exclude from the voting configuration. If specified, you may
356+
not also specify ?node_ids.
357+
:arg timeout: Explicit operation timeout Default: 30s
358+
"""
359+
return self.transport.perform_request(
360+
"POST", "/_cluster/voting_config_exclusions", params=params, headers=headers
361+
)

elasticsearch/client/eql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class EqlClient(NamespacedClient):
1010
def search(self, index, body, params=None, headers=None):
1111
"""
1212
Returns results matching a query expressed in Event Query Language (EQL)
13-
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/eql.html>`_
13+
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/eql-search-api.html>`_
1414
1515
:arg index: The name of the index to scope the operation
1616
:arg body: Eql request body. Use the `query` to limit the query

elasticsearch/client/indices.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ def flush(self, index=None, params=None, headers=None):
8282
"POST", _make_path(index, "_flush"), params=params, headers=headers
8383
)
8484

85-
@query_params(
86-
"master_timeout", "prefer_v2_templates", "timeout", "wait_for_active_shards"
87-
)
85+
@query_params("master_timeout", "timeout", "wait_for_active_shards")
8886
def create(self, index, body=None, params=None, headers=None):
8987
"""
9088
Creates an index with optional settings and mappings.
@@ -94,8 +92,6 @@ def create(self, index, body=None, params=None, headers=None):
9492
:arg body: The configuration for the index (`settings` and
9593
`mappings`)
9694
:arg master_timeout: Specify timeout for connection to master
97-
:arg prefer_v2_templates: favor V2 templates instead of V1
98-
templates during index creation
9995
:arg timeout: Explicit operation timeout
10096
:arg wait_for_active_shards: Set the number of active shards to
10197
wait for before the operation returns.
@@ -979,13 +975,7 @@ def split(self, index, target, body=None, params=None, headers=None):
979975
body=body,
980976
)
981977

982-
@query_params(
983-
"dry_run",
984-
"master_timeout",
985-
"prefer_v2_templates",
986-
"timeout",
987-
"wait_for_active_shards",
988-
)
978+
@query_params("dry_run", "master_timeout", "timeout", "wait_for_active_shards")
989979
def rollover(self, alias, body=None, new_index=None, params=None, headers=None):
990980
"""
991981
Updates an alias to point to a new index when the existing index is considered
@@ -1000,8 +990,6 @@ def rollover(self, alias, body=None, new_index=None, params=None, headers=None):
1000990
validated but not actually performed even if a condition matches. The
1001991
default is false
1002992
:arg master_timeout: Specify timeout for connection to master
1003-
:arg prefer_v2_templates: favor V2 templates instead of V1
1004-
templates during automatic index creation
1005993
:arg timeout: Explicit operation timeout
1006994
:arg wait_for_active_shards: Set the number of active shards to
1007995
wait for on the newly created rollover index before the operation
@@ -1299,20 +1287,19 @@ def get_index_template(self, name=None, params=None, headers=None):
12991287
"GET", _make_path("_index_template", name), params=params, headers=headers
13001288
)
13011289

1302-
@query_params("create", "master_timeout", "order")
1290+
@query_params("cause", "create", "master_timeout")
13031291
def put_index_template(self, name, body, params=None, headers=None):
13041292
"""
13051293
Creates or updates an index template.
13061294
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html>`_
13071295
13081296
:arg name: The name of the template
13091297
:arg body: The template definition
1298+
:arg cause: User defined reason for creating/updating the index
1299+
template
13101300
:arg create: Whether the index template should only be added if
13111301
new or can also replace an existing one
13121302
:arg master_timeout: Specify timeout for connection to master
1313-
:arg order: The order for this template when merging multiple
1314-
matching ones (higher numbers are merged later, overriding the lower
1315-
numbers)
13161303
"""
13171304
for param in (name, body):
13181305
if param in SKIP_IN_PATH:
@@ -1346,3 +1333,32 @@ def exists_index_template(self, name, params=None, headers=None):
13461333
return self.transport.perform_request(
13471334
"HEAD", _make_path("_index_template", name), params=params, headers=headers
13481335
)
1336+
1337+
@query_params("cause", "create", "master_timeout")
1338+
def simulate_index_template(self, name, body=None, params=None, headers=None):
1339+
"""
1340+
Simulate matching the given index name against the index templates in the
1341+
system
1342+
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html>`_
1343+
1344+
:arg name: The name of the index (it must be a concrete index
1345+
name)
1346+
:arg body: New index template definition, which will be included
1347+
in the simulation, as if it already exists in the system
1348+
:arg cause: User defined reason for dry-run creating the new
1349+
template for simulation purposes
1350+
:arg create: Whether the index template we optionally defined in
1351+
the body should only be dry-run added if new or can also replace an
1352+
existing one
1353+
:arg master_timeout: Specify timeout for connection to master
1354+
"""
1355+
if name in SKIP_IN_PATH:
1356+
raise ValueError("Empty value passed for a required argument 'name'.")
1357+
1358+
return self.transport.perform_request(
1359+
"POST",
1360+
_make_path("_index_template", "_simulate_index", name),
1361+
params=params,
1362+
headers=headers,
1363+
body=body,
1364+
)

elasticsearch/client/searchable_snapshots.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class SearchableSnapshotsClient(NamespacedClient):
99
@query_params("allow_no_indices", "expand_wildcards", "ignore_unavailable")
1010
def clear_cache(self, index=None, params=None, headers=None):
1111
"""
12+
Clear the cache of searchable snapshots.
1213
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/searchable-snapshots-api-clear-cache.html>`_
1314
1415
:arg index: A comma-separated list of index name to limit the
@@ -32,6 +33,7 @@ def clear_cache(self, index=None, params=None, headers=None):
3233
@query_params("master_timeout", "wait_for_completion")
3334
def mount(self, repository, snapshot, body, params=None, headers=None):
3435
"""
36+
Mount a snapshot as a searchable index.
3537
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/searchable-snapshots-api-mount-snapshot.html>`_
3638
3739
:arg repository: The name of the repository containing the
@@ -59,6 +61,7 @@ def mount(self, repository, snapshot, body, params=None, headers=None):
5961
@query_params()
6062
def repository_stats(self, repository, params=None, headers=None):
6163
"""
64+
Retrieve usage statistics about a snapshot repository.
6265
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/searchable-snapshots-repository-stats.html>`_
6366
6467
:arg repository: The repository for which to get the stats for
@@ -76,6 +79,7 @@ def repository_stats(self, repository, params=None, headers=None):
7679
@query_params()
7780
def stats(self, index=None, params=None, headers=None):
7881
"""
82+
Retrieve various statistics about searchable snapshots.
7983
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/searchable-snapshots-api-stats.html>`_
8084
8185
:arg index: A comma-separated list of index names

elasticsearch/helpers/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def tearDown(self):
6363
index="*", ignore=404, expand_wildcards=expand_wildcards
6464
)
6565
self.client.indices.delete_template(name="*", ignore=404)
66+
self.client.indices.delete_index_template(name="*", ignore=404)
6667

6768
@property
6869
def es_version(self):

test_elasticsearch/test_server/test_common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
"TestIndicesGetAlias10Basic",
4747
# Disallowing expensive queries is 7.7+
4848
"TestSearch320DisallowQueries",
49+
# Extra warning due to v2 index templates
50+
"TestIndicesPutTemplate10Basic",
51+
# Depends on order of response which is random.
52+
"TestIndicesSimulateIndexTemplate10Basic",
53+
# simulate index template doesn't work with ?q=
54+
"TestSearch60QueryString",
55+
"TestExplain30QueryString",
4956
}
5057
}
5158

0 commit comments

Comments
 (0)