Skip to content

Commit

Permalink
Add Index v2 and Voting Config APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed May 12, 2020
1 parent 04fee08 commit 242adb0
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 34 deletions.
12 changes: 0 additions & 12 deletions elasticsearch/client/__init__.py
Expand Up @@ -302,7 +302,6 @@ def info(self, params=None, headers=None):

@query_params(
"pipeline",
"prefer_v2_templates",
"refresh",
"routing",
"timeout",
Expand All @@ -322,8 +321,6 @@ def create(self, index, id, body, doc_type=None, params=None, headers=None):
:arg doc_type: The type of the document
:arg pipeline: The pipeline id to preprocess incoming documents
with
:arg prefer_v2_templates: favor V2 templates instead of V1
templates during automatic index creation
:arg refresh: If `true` then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh
to make this operation visible to search, if `false` (the default) then
Expand Down Expand Up @@ -361,7 +358,6 @@ def create(self, index, id, body, doc_type=None, params=None, headers=None):
"if_seq_no",
"op_type",
"pipeline",
"prefer_v2_templates",
"refresh",
"routing",
"timeout",
Expand All @@ -388,8 +384,6 @@ def index(self, index, body, id=None, params=None, headers=None):
without an explicit document ID Valid choices: index, create
:arg pipeline: The pipeline id to preprocess incoming documents
with
:arg prefer_v2_templates: favor V2 templates instead of V1
templates during automatic index creation
:arg refresh: If `true` then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh
to make this operation visible to search, if `false` (the default) then
Expand Down Expand Up @@ -422,7 +416,6 @@ def index(self, index, body, id=None, params=None, headers=None):
"_source_excludes",
"_source_includes",
"pipeline",
"prefer_v2_templates",
"refresh",
"routing",
"timeout",
Expand All @@ -447,8 +440,6 @@ def bulk(self, body, index=None, doc_type=None, params=None, headers=None):
return from the _source field, can be overridden on each sub-request
:arg pipeline: The pipeline id to preprocess incoming documents
with
:arg prefer_v2_templates: favor V2 templates instead of V1
templates during automatic index creation
:arg refresh: If `true` then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh
to make this operation visible to search, if `false` (the default) then
Expand Down Expand Up @@ -1533,7 +1524,6 @@ def search_shards(self, index=None, params=None, headers=None):
"if_primary_term",
"if_seq_no",
"lang",
"prefer_v2_templates",
"refresh",
"retry_on_conflict",
"routing",
Expand Down Expand Up @@ -1563,8 +1553,6 @@ def update(self, index, id, body, doc_type=None, params=None, headers=None):
operation that has changed the document has the specified sequence
number
:arg lang: The script language (default: painless)
:arg prefer_v2_templates: favor V2 templates instead of V1
templates during automatic index creation
:arg refresh: If `true` then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh
to make this operation visible to search, if `false` (the default) then
Expand Down
3 changes: 3 additions & 0 deletions elasticsearch/client/autoscaling.py
Expand Up @@ -20,6 +20,7 @@ def get_autoscaling_decision(self, params=None, headers=None):
@query_params()
def delete_autoscaling_policy(self, name, params=None, headers=None):
"""
Deletes an autoscaling policy.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/autoscaling-delete-autoscaling-policy.html>`_
:arg name: the name of the autoscaling policy
Expand All @@ -37,6 +38,7 @@ def delete_autoscaling_policy(self, name, params=None, headers=None):
@query_params()
def put_autoscaling_policy(self, name, body, params=None, headers=None):
"""
Creates a new autoscaling policy.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/autoscaling-put-autoscaling-policy.html>`_
:arg name: the name of the autoscaling policy
Expand All @@ -57,6 +59,7 @@ def put_autoscaling_policy(self, name, body, params=None, headers=None):
@query_params()
def get_autoscaling_policy(self, name, params=None, headers=None):
"""
Retrieves an autoscaling policy.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/autoscaling-get-autoscaling-policy.html>`_
:arg name: the name of the autoscaling policy
Expand Down
6 changes: 3 additions & 3 deletions elasticsearch/client/cat.py
Expand Up @@ -326,7 +326,7 @@ def pending_tasks(self, params=None, headers=None):
"GET", "/_cat/pending_tasks", params=params, headers=headers
)

@query_params("format", "h", "help", "local", "master_timeout", "s", "size", "v")
@query_params("format", "h", "help", "local", "master_timeout", "s", "time", "v")
def thread_pool(self, thread_pool_patterns=None, params=None, headers=None):
"""
Returns cluster-wide thread pool statistics per node. By default the active,
Expand All @@ -345,8 +345,8 @@ def thread_pool(self, thread_pool_patterns=None, params=None, headers=None):
to master node
:arg s: Comma-separated list of column names or column aliases
to sort by
:arg size: The multiplier in which to display values Valid
choices: , k, m, g, t, p
:arg time: The unit in which to display time values Valid
choices: d, h, m, s, ms, micros, nanos
:arg v: Verbose mode. Display column headers
"""
return self.transport.perform_request(
Expand Down
35 changes: 35 additions & 0 deletions elasticsearch/client/cluster.py
Expand Up @@ -324,3 +324,38 @@ def exists_component_template(self, name, params=None, headers=None):
params=params,
headers=headers,
)

@query_params("wait_for_removal")
def delete_voting_config_exclusions(self, params=None, headers=None):
"""
Clears cluster voting config exclusions.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html>`_
:arg wait_for_removal: Specifies whether to wait for all
excluded nodes to be removed from the cluster before clearing the voting
configuration exclusions list. Default: True
"""
return self.transport.perform_request(
"DELETE",
"/_cluster/voting_config_exclusions",
params=params,
headers=headers,
)

@query_params("node_ids", "node_names", "timeout")
def post_voting_config_exclusions(self, params=None, headers=None):
"""
Updates the cluster voting config exclusions by node ids or node names.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html>`_
:arg node_ids: A comma-separated list of the persistent ids of
the nodes to exclude from the voting configuration. If specified, you
may not also specify ?node_names.
:arg node_names: A comma-separated list of the names of the
nodes to exclude from the voting configuration. If specified, you may
not also specify ?node_ids.
:arg timeout: Explicit operation timeout Default: 30s
"""
return self.transport.perform_request(
"POST", "/_cluster/voting_config_exclusions", params=params, headers=headers
)
2 changes: 1 addition & 1 deletion elasticsearch/client/eql.py
Expand Up @@ -10,7 +10,7 @@ class EqlClient(NamespacedClient):
def search(self, index, body, params=None, headers=None):
"""
Returns results matching a query expressed in Event Query Language (EQL)
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/eql.html>`_
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/eql-search-api.html>`_
:arg index: The name of the index to scope the operation
:arg body: Eql request body. Use the `query` to limit the query
Expand Down
52 changes: 34 additions & 18 deletions elasticsearch/client/indices.py
Expand Up @@ -82,9 +82,7 @@ def flush(self, index=None, params=None, headers=None):
"POST", _make_path(index, "_flush"), params=params, headers=headers
)

@query_params(
"master_timeout", "prefer_v2_templates", "timeout", "wait_for_active_shards"
)
@query_params("master_timeout", "timeout", "wait_for_active_shards")
def create(self, index, body=None, params=None, headers=None):
"""
Creates an index with optional settings and mappings.
Expand All @@ -94,8 +92,6 @@ def create(self, index, body=None, params=None, headers=None):
:arg body: The configuration for the index (`settings` and
`mappings`)
:arg master_timeout: Specify timeout for connection to master
:arg prefer_v2_templates: favor V2 templates instead of V1
templates during index creation
:arg timeout: Explicit operation timeout
:arg wait_for_active_shards: Set the number of active shards to
wait for before the operation returns.
Expand Down Expand Up @@ -979,13 +975,7 @@ def split(self, index, target, body=None, params=None, headers=None):
body=body,
)

@query_params(
"dry_run",
"master_timeout",
"prefer_v2_templates",
"timeout",
"wait_for_active_shards",
)
@query_params("dry_run", "master_timeout", "timeout", "wait_for_active_shards")
def rollover(self, alias, body=None, new_index=None, params=None, headers=None):
"""
Updates an alias to point to a new index when the existing index is considered
Expand All @@ -1000,8 +990,6 @@ def rollover(self, alias, body=None, new_index=None, params=None, headers=None):
validated but not actually performed even if a condition matches. The
default is false
:arg master_timeout: Specify timeout for connection to master
:arg prefer_v2_templates: favor V2 templates instead of V1
templates during automatic index creation
:arg timeout: Explicit operation timeout
:arg wait_for_active_shards: Set the number of active shards to
wait for on the newly created rollover index before the operation
Expand Down Expand Up @@ -1299,20 +1287,19 @@ def get_index_template(self, name=None, params=None, headers=None):
"GET", _make_path("_index_template", name), params=params, headers=headers
)

@query_params("create", "master_timeout", "order")
@query_params("cause", "create", "master_timeout")
def put_index_template(self, name, body, params=None, headers=None):
"""
Creates or updates an index template.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html>`_
:arg name: The name of the template
:arg body: The template definition
:arg cause: User defined reason for creating/updating the index
template
:arg create: Whether the index template should only be added if
new or can also replace an existing one
:arg master_timeout: Specify timeout for connection to master
:arg order: The order for this template when merging multiple
matching ones (higher numbers are merged later, overriding the lower
numbers)
"""
for param in (name, body):
if param in SKIP_IN_PATH:
Expand Down Expand Up @@ -1346,3 +1333,32 @@ def exists_index_template(self, name, params=None, headers=None):
return self.transport.perform_request(
"HEAD", _make_path("_index_template", name), params=params, headers=headers
)

@query_params("cause", "create", "master_timeout")
def simulate_index_template(self, name, body=None, params=None, headers=None):
"""
Simulate matching the given index name against the index templates in the
system
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html>`_
:arg name: The name of the index (it must be a concrete index
name)
:arg body: New index template definition, which will be included
in the simulation, as if it already exists in the system
:arg cause: User defined reason for dry-run creating the new
template for simulation purposes
:arg create: Whether the index template we optionally defined in
the body should only be dry-run added if new or can also replace an
existing one
:arg master_timeout: Specify timeout for connection to master
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'name'.")

return self.transport.perform_request(
"POST",
_make_path("_index_template", "_simulate_index", name),
params=params,
headers=headers,
body=body,
)
4 changes: 4 additions & 0 deletions elasticsearch/client/searchable_snapshots.py
Expand Up @@ -9,6 +9,7 @@ class SearchableSnapshotsClient(NamespacedClient):
@query_params("allow_no_indices", "expand_wildcards", "ignore_unavailable")
def clear_cache(self, index=None, params=None, headers=None):
"""
Clear the cache of searchable snapshots.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/searchable-snapshots-api-clear-cache.html>`_
:arg index: A comma-separated list of index name to limit the
Expand All @@ -32,6 +33,7 @@ def clear_cache(self, index=None, params=None, headers=None):
@query_params("master_timeout", "wait_for_completion")
def mount(self, repository, snapshot, body, params=None, headers=None):
"""
Mount a snapshot as a searchable index.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/searchable-snapshots-api-mount-snapshot.html>`_
:arg repository: The name of the repository containing the
Expand Down Expand Up @@ -59,6 +61,7 @@ def mount(self, repository, snapshot, body, params=None, headers=None):
@query_params()
def repository_stats(self, repository, params=None, headers=None):
"""
Retrieve usage statistics about a snapshot repository.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/searchable-snapshots-repository-stats.html>`_
:arg repository: The repository for which to get the stats for
Expand All @@ -76,6 +79,7 @@ def repository_stats(self, repository, params=None, headers=None):
@query_params()
def stats(self, index=None, params=None, headers=None):
"""
Retrieve various statistics about searchable snapshots.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/searchable-snapshots-api-stats.html>`_
:arg index: A comma-separated list of index names
Expand Down
1 change: 1 addition & 0 deletions elasticsearch/helpers/test.py
Expand Up @@ -63,6 +63,7 @@ def tearDown(self):
index="*", ignore=404, expand_wildcards=expand_wildcards
)
self.client.indices.delete_template(name="*", ignore=404)
self.client.indices.delete_index_template(name="*", ignore=404)

@property
def es_version(self):
Expand Down
7 changes: 7 additions & 0 deletions test_elasticsearch/test_server/test_common.py
Expand Up @@ -46,6 +46,13 @@
"TestIndicesGetAlias10Basic",
# Disallowing expensive queries is 7.7+
"TestSearch320DisallowQueries",
# Extra warning due to v2 index templates
"TestIndicesPutTemplate10Basic",
# Depends on order of response which is random.
"TestIndicesSimulateIndexTemplate10Basic",
# simulate index template doesn't work with ?q=
"TestSearch60QueryString",
"TestExplain30QueryString",
}
}

Expand Down

0 comments on commit 242adb0

Please sign in to comment.