diff --git a/elasticsearch/client/__init__.py b/elasticsearch/client/__init__.py index 5f60581d..cd87af0e 100644 --- a/elasticsearch/client/__init__.py +++ b/elasticsearch/client/__init__.py @@ -30,6 +30,9 @@ from .security import SecurityClient from .sql import SqlClient from .ssl import SslClient from .watcher import WatcherClient +from .enrich import EnrichClient +from .slm import SlmClient +from .transform import TransformClient logger = logging.getLogger("elasticsearch") @@ -248,6 +251,9 @@ class Elasticsearch(object): self.sql = SqlClient(self) self.ssl = SslClient(self) self.watcher = WatcherClient(self) + self.enrich = EnrichClient(self) + self.slm = SlmClient(self) + self.transform = TransformClient(self) def __repr__(self): try: @@ -277,8 +283,9 @@ class Elasticsearch(object): @query_params() def ping(self, params=None): """ - Returns True if the cluster is up, False otherwise. - ``_ + Returns whether the cluster is running. + ``_ + """ try: return self.transport.perform_request("HEAD", "/", params=params) @@ -288,122 +295,466 @@ class Elasticsearch(object): @query_params() def info(self, params=None): """ - Get the basic info from the current cluster. - ``_ + Returns basic information about the cluster. + ``_ + """ return self.transport.perform_request("GET", "/", params=params) @query_params( - "parent", "pipeline", "refresh", "routing", "timeout", - "timestamp", - "ttl", "version", "version_type", "wait_for_active_shards", ) - def create(self, index, id, body, doc_type="_doc", params=None): + def create(self, index, id, body, doc_type=None, params=None): """ - Adds a typed JSON document in a specific index, making it searchable. - Behind the scenes this method calls index(..., op_type='create') - ``_ + Creates a new document in the index. Returns a 409 response when a document + with a same ID already exists in the index. + ``_ :arg index: The name of the index :arg id: Document ID :arg body: The document - :arg parent: ID of the parent document - :arg pipeline: The pipeline id to preprocess incoming documents with - :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 do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg doc_type: The type of the document + :arg pipeline: The pipeline id to preprocess incoming documents + with + :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 + do nothing with refreshes. Valid choices: true, false, wait_for :arg routing: Specific routing value :arg timeout: Explicit operation timeout - :arg timestamp: Explicit timestamp for the document - :arg ttl: Expiration time for the document :arg version: Explicit version number for concurrency control - :arg version_type: Specific version type, valid choices are: 'internal', - 'external', 'external_gte', 'force' - :arg wait_for_active_shards: Sets the number of shard copies that must - be active before proceeding with the index operation. Defaults to 1, - meaning the primary shard only. Set to `all` for all shard copies, - otherwise set to any non-negative value less than or equal to the - total number of copies for the shard (number of replicas + 1) + :arg version_type: Specific version type Valid choices: + internal, external, external_gte + :arg wait_for_active_shards: Sets the number of shard copies + that must be active before proceeding with the index operation. Defaults + to 1, meaning the primary shard only. Set to `all` for all shard copies, + otherwise set to any non-negative value less than or equal to the total + number of copies for the shard (number of replicas + 1) """ for param in (index, id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path(index, doc_type, id, "_create"), params=params, body=body ) @query_params( - "if_seq_no", "if_primary_term", + "if_seq_no", "op_type", - "parent", "pipeline", "refresh", "routing", "timeout", - "timestamp", - "ttl", "version", "version_type", "wait_for_active_shards", ) - def index(self, index, body, doc_type="_doc", id=None, params=None): + def index(self, index, body, doc_type=None, id=None, params=None): """ - Adds or updates a typed JSON document in a specific index, making it searchable. - ``_ + Creates or updates a document in an index. + ``_ :arg index: The name of the index :arg body: The document + :arg doc_type: The type of the document :arg id: Document ID - :arg if_primary_term: only perform the index operation if the last - operation that has changed the document has the specified primary + :arg if_primary_term: only perform the index operation if the + last operation that has changed the document has the specified primary term - :arg if_seq_no: only perform the index operation if the last operation - that has changed the document has the specified sequence number - :arg doc_type: Document type, defaults to `_doc`. Not used on ES 7 clusters. - :arg op_type: Explicit operation type, default 'index', valid choices - are: 'index', 'create' - :arg parent: ID of the parent document - :arg pipeline: The pipeline id to preprocess incoming documents with - :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 do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg if_seq_no: only perform the index operation if the last + operation that has changed the document has the specified sequence + number + :arg op_type: Explicit operation type. Defaults to `index` for + requests with an explicit document ID, and to `create`for requests + without an explicit document ID Valid choices: index, create + :arg pipeline: The pipeline id to preprocess incoming documents + with + :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 + do nothing with refreshes. Valid choices: true, false, wait_for :arg routing: Specific routing value :arg timeout: Explicit operation timeout - :arg timestamp: Explicit timestamp for the document - :arg ttl: Expiration time for the document :arg version: Explicit version number for concurrency control - :arg version_type: Specific version type, valid choices are: 'internal', - 'external', 'external_gte', 'force' - :arg wait_for_active_shards: Sets the number of shard copies that must - be active before proceeding with the index operation. Defaults to 1, - meaning the primary shard only. Set to `all` for all shard copies, - otherwise set to any non-negative value less than or equal to the - total number of copies for the shard (number of replicas + 1) + :arg version_type: Specific version type Valid choices: + internal, external, external_gte + :arg wait_for_active_shards: Sets the number of shard copies + that must be active before proceeding with the index operation. Defaults + to 1, meaning the primary shard only. Set to `all` for all shard copies, + otherwise set to any non-negative value less than or equal to the total + number of copies for the shard (number of replicas + 1) """ for param in (index, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + + if doc_type is None: + doc_type = "_doc" + return self.transport.perform_request( - "POST", _make_path(index, doc_type, id), params=params, body=body + "POST" if id in SKIP_IN_PATH else "PUT", + _make_path(index, doc_type, id), + params=params, + body=body, + ) + + @query_params( + "_source", + "_source_excludes", + "_source_includes", + "doc_type", + "pipeline", + "refresh", + "routing", + "timeout", + "wait_for_active_shards", + ) + def bulk(self, body, index=None, doc_type=None, params=None): + """ + Allows to perform multiple index/update/delete operations in a single request. + ``_ + + :arg body: The operation definition and data (action-data + pairs), separated by newlines + :arg index: Default index for items which don't provide one + :arg doc_type: Default document type for items which don't + provide one + :arg _source: True or false to return the _source field or not, + or default list of fields to return, can be overridden on each sub- + request + :arg _source_excludes: Default list of fields to exclude from + the returned _source field, can be overridden on each sub-request + :arg _source_includes: Default list of fields to extract and + return from the _source field, can be overridden on each sub-request + :arg doc_type: Default document type for items which don't + provide one + :arg pipeline: The pipeline id to preprocess incoming documents + with + :arg refresh: If `true` then refresh the effected 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 + do nothing with refreshes. Valid choices: true, false, wait_for + :arg routing: Specific routing value + :arg timeout: Explicit operation timeout + :arg wait_for_active_shards: Sets the number of shard copies + that must be active before proceeding with the bulk operation. Defaults + to 1, meaning the primary shard only. Set to `all` for all shard copies, + otherwise set to any non-negative value less than or equal to the total + number of copies for the shard (number of replicas + 1) + """ + if body in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'body'.") + + body = self._bulk_body(body) + return self.transport.perform_request( + "POST", _make_path(index, doc_type, "_bulk"), params=params, body=body + ) + + @query_params() + def clear_scroll(self, body=None, scroll_id=None, params=None): + """ + Explicitly clears the search context for a scroll. + ``_ + + :arg body: A comma-separated list of scroll IDs to clear if none + was specified via the scroll_id parameter + :arg scroll_id: A comma-separated list of scroll IDs to clear + """ + if scroll_id in SKIP_IN_PATH and body in SKIP_IN_PATH: + raise ValueError("You need to supply scroll_id or body.") + elif scroll_id and not body: + body = {"scroll_id": [scroll_id]} + elif scroll_id: + params["scroll_id"] = scroll_id + + return self.transport.perform_request( + "DELETE", "/_search/scroll", params=params, body=body + ) + + @query_params( + "allow_no_indices", + "analyze_wildcard", + "analyzer", + "default_operator", + "df", + "expand_wildcards", + "ignore_throttled", + "ignore_unavailable", + "lenient", + "min_score", + "preference", + "q", + "routing", + "terminate_after", + ) + def count(self, body=None, index=None, doc_type=None, params=None): + """ + Returns number of documents matching a query. + ``_ + + :arg body: A query to restrict the results specified with the + Query DSL (optional) + :arg index: A comma-separated list of indices to restrict the + results + :arg doc_type: A comma-separated list of types to restrict the + results + :arg allow_no_indices: Whether to ignore if a wildcard indices + expression resolves into no concrete indices. (This includes `_all` + string or when no indices have been specified) + :arg analyze_wildcard: Specify whether wildcard and prefix + queries should be analyzed (default: false) + :arg analyzer: The analyzer to use for the query string + :arg default_operator: The default operator for query string + query (AND or OR) Valid choices: AND, OR Default: OR + :arg df: The field to use as default where no field prefix is + given in the query string + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_throttled: Whether specified concrete, expanded or + aliased indices should be ignored when throttled + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg lenient: Specify whether format-based query failures (such + as providing text to a numeric field) should be ignored + :arg min_score: Include only documents with a specific `_score` + value in the result + :arg preference: Specify the node or shard the operation should + be performed on (default: random) + :arg q: Query in the Lucene query string syntax + :arg routing: A comma-separated list of specific routing values + :arg terminate_after: The maximum count for each shard, upon + reaching which the query execution will terminate early + """ + return self.transport.perform_request( + "POST", _make_path(index, doc_type, "_count"), params=params, body=body + ) + + @query_params( + "if_primary_term", + "if_seq_no", + "refresh", + "routing", + "timeout", + "version", + "version_type", + "wait_for_active_shards", + ) + def delete(self, index, id, doc_type=None, params=None): + """ + Removes a document from the index. + ``_ + + :arg index: The name of the index + :arg id: The document ID + :arg doc_type: The type of the document + :arg if_primary_term: only perform the delete operation if the + last operation that has changed the document has the specified primary + term + :arg if_seq_no: only perform the delete operation if the last + operation that has changed the document has the specified sequence + number + :arg refresh: If `true` then refresh the effected 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 + do nothing with refreshes. Valid choices: true, false, wait_for + :arg routing: Specific routing value + :arg timeout: Explicit operation timeout + :arg version: Explicit version number for concurrency control + :arg version_type: Specific version type Valid choices: + internal, external, external_gte, force + :arg wait_for_active_shards: Sets the number of shard copies + that must be active before proceeding with the delete operation. + Defaults to 1, meaning the primary shard only. Set to `all` for all + shard copies, otherwise set to any non-negative value less than or equal + to the total number of copies for the shard (number of replicas + 1) + """ + for param in (index, id): + if param in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument.") + + if doc_type is None: + doc_type = "_doc" + + return self.transport.perform_request( + "DELETE", _make_path(index, doc_type, id), params=params + ) + + @query_params( + "_source", + "_source_excludes", + "_source_includes", + "allow_no_indices", + "analyze_wildcard", + "conflicts", + "default_operator", + "df", + "expand_wildcards", + "from_", + "ignore_unavailable", + "lenient", + "max_docs", + "preference", + "q", + "refresh", + "request_cache", + "requests_per_second", + "routing", + "scroll", + "scroll_size", + "search_timeout", + "search_type", + "size", + "slices", + "sort", + "stats", + "terminate_after", + "timeout", + "version", + "wait_for_active_shards", + "wait_for_completion", + ) + def delete_by_query(self, index, body, doc_type=None, params=None): + """ + Deletes documents matching the provided query. + ``_ + + :arg index: A comma-separated list of index names to search; use + `_all` or empty string to perform the operation on all indices + :arg body: The search definition using the Query DSL + :arg doc_type: A comma-separated list of document types to + search; leave empty to perform the operation on all types + :arg _source: True or false to return the _source field or not, + or a list of fields to return + :arg _source_excludes: A list of fields to exclude from the + returned _source field + :arg _source_includes: A list of fields to extract and return + from the _source field + :arg allow_no_indices: Whether to ignore if a wildcard indices + expression resolves into no concrete indices. (This includes `_all` + string or when no indices have been specified) + :arg analyze_wildcard: Specify whether wildcard and prefix + queries should be analyzed (default: false) + :arg conflicts: What to do when the delete by query hits version + conflicts? Valid choices: abort, proceed Default: abort + :arg default_operator: The default operator for query string + query (AND or OR) Valid choices: AND, OR Default: OR + :arg df: The field to use as default where no field prefix is + given in the query string + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg from_: Starting offset (default: 0) + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg lenient: Specify whether format-based query failures (such + as providing text to a numeric field) should be ignored + :arg max_docs: Maximum number of documents to process (default: + all documents) + :arg preference: Specify the node or shard the operation should + be performed on (default: random) + :arg q: Query in the Lucene query string syntax + :arg refresh: Should the effected indexes be refreshed? + :arg request_cache: Specify if request cache should be used for + this request or not, defaults to index level setting + :arg requests_per_second: The throttle for this request in sub- + requests per second. -1 means no throttle. + :arg routing: A comma-separated list of specific routing values + :arg scroll: Specify how long a consistent view of the index + should be maintained for scrolled search + :arg scroll_size: Size on the scroll request powering the delete + by query + :arg search_timeout: Explicit timeout for each search request. + Defaults to no timeout. + :arg search_type: Search operation type Valid choices: + query_then_fetch, dfs_query_then_fetch + :arg size: Deprecated, please use `max_docs` instead + :arg slices: The number of slices this task should be divided + into. Defaults to 1 meaning the task isn't sliced into subtasks. + Default: 1 + :arg sort: A comma-separated list of : pairs + :arg stats: Specific 'tag' of the request for logging and + statistical purposes + :arg terminate_after: The maximum number of documents to collect + for each shard, upon reaching which the query execution will terminate + early. + :arg timeout: Time each individual bulk request should wait for + shards that are unavailable. Default: 1m + :arg version: Specify whether to return document version as part + of a hit + :arg wait_for_active_shards: Sets the number of shard copies + that must be active before proceeding with the delete by query + operation. Defaults to 1, meaning the primary shard only. Set to `all` + for all shard copies, otherwise set to any non-negative value less than + or equal to the total number of copies for the shard (number of replicas + + 1) + :arg wait_for_completion: Should the request should block until + the delete by query is complete. Default: True + """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + + for param in (index, body): + if param in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument.") + + return self.transport.perform_request( + "POST", + _make_path(index, doc_type, "_delete_by_query"), + params=params, + body=body, + ) + + @query_params("requests_per_second") + def delete_by_query_rethrottle(self, task_id, params=None): + """ + Changes the number of requests per second for a particular Delete By Query + operation. + ``_ + + :arg task_id: The task id to rethrottle + :arg requests_per_second: The throttle to set on this request in + floating sub-requests per second. -1 means set no throttle. + """ + if task_id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'task_id'.") + + return self.transport.perform_request( + "POST", + _make_path("_delete_by_query", task_id, "_rethrottle"), + params=params, + ) + + @query_params("master_timeout", "timeout") + def delete_script(self, id, params=None): + """ + Deletes a script. + ``_ + + :arg id: Script ID + :arg master_timeout: Specify timeout for connection to master + :arg timeout: Explicit operation timeout + """ + if id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'id'.") + + return self.transport.perform_request( + "DELETE", _make_path("_scripts", id), params=params ) @query_params( "_source", "_source_excludes", "_source_includes", - "parent", "preference", "realtime", "refresh", @@ -412,36 +763,41 @@ class Elasticsearch(object): "version", "version_type", ) - def exists(self, index, id, doc_type="_doc", params=None): + def exists(self, index, id, doc_type=None, params=None): """ - Returns a boolean indicating whether or not given document exists in Elasticsearch. - ``_ + Returns information about whether a document exists in an index. + ``_ :arg index: The name of the index :arg id: The document ID - :arg _source: True or false to return the _source field or not, or a - list of fields to return - :arg _source_excludes: A list of fields to exclude from the returned - _source field - :arg _source_includes: A list of fields to extract and return from the - _source field - :arg parent: The ID of the parent document - :arg preference: Specify the node or shard the operation should be - performed on (default: random) - :arg realtime: Specify whether to perform the operation in realtime or - search mode + :arg doc_type: The type of the document (use `_all` to fetch the + first document matching the ID across all types) + :arg _source: True or false to return the _source field or not, + or a list of fields to return + :arg _source_excludes: A list of fields to exclude from the + returned _source field + :arg _source_includes: A list of fields to extract and return + from the _source field + :arg preference: Specify the node or shard the operation should + be performed on (default: random) + :arg realtime: Specify whether to perform the operation in + realtime or search mode :arg refresh: Refresh the shard containing the document before performing the operation :arg routing: Specific routing value - :arg stored_fields: A comma-separated list of stored fields to return in - the response + :arg stored_fields: A comma-separated list of stored fields to + return in the response :arg version: Explicit version number for concurrency control - :arg version_type: Specific version type, valid choices are: 'internal', - 'external', 'external_gte', 'force' + :arg version_type: Specific version type Valid choices: + internal, external, external_gte, force """ for param in (index, id): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + + if doc_type is None: + doc_type = "_doc" + return self.transport.perform_request( "HEAD", _make_path(index, doc_type, id), params=params ) @@ -450,7 +806,6 @@ class Elasticsearch(object): "_source", "_source_excludes", "_source_includes", - "parent", "preference", "realtime", "refresh", @@ -460,31 +815,34 @@ class Elasticsearch(object): ) def exists_source(self, index, id, doc_type=None, params=None): """ - ``_ + Returns information about whether a document source exists in an index. + ``_ :arg index: The name of the index :arg id: The document ID - :arg _source: True or false to return the _source field or not, or a - list of fields to return - :arg _source_excludes: A list of fields to exclude from the returned - _source field - :arg _source_includes: A list of fields to extract and return from the - _source field - :arg parent: The ID of the parent document - :arg preference: Specify the node or shard the operation should be - performed on (default: random) - :arg realtime: Specify whether to perform the operation in realtime or - search mode + :arg doc_type: The type of the document; deprecated and optional + starting with 7.0 + :arg _source: True or false to return the _source field or not, + or a list of fields to return + :arg _source_excludes: A list of fields to exclude from the + returned _source field + :arg _source_includes: A list of fields to extract and return + from the _source field + :arg preference: Specify the node or shard the operation should + be performed on (default: random) + :arg realtime: Specify whether to perform the operation in + realtime or search mode :arg refresh: Refresh the shard containing the document before performing the operation :arg routing: Specific routing value :arg version: Explicit version number for concurrency control - :arg version_type: Specific version type, valid choices are: 'internal', - 'external', 'external_gte', 'force' + :arg version_type: Specific version type Valid choices: + internal, external, external_gte, force """ for param in (index, id): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "HEAD", _make_path(index, doc_type, id, "_source"), params=params ) @@ -493,7 +851,90 @@ class Elasticsearch(object): "_source", "_source_excludes", "_source_includes", - "parent", + "analyze_wildcard", + "analyzer", + "default_operator", + "df", + "lenient", + "preference", + "q", + "routing", + "stored_fields", + ) + def explain(self, index, id, body=None, doc_type=None, params=None): + """ + Returns information about why a specific matches (or doesn't match) a query. + ``_ + + :arg index: The name of the index + :arg id: The document ID + :arg body: The query definition using the Query DSL + :arg doc_type: The type of the document + :arg _source: True or false to return the _source field or not, + or a list of fields to return + :arg _source_excludes: A list of fields to exclude from the + returned _source field + :arg _source_includes: A list of fields to extract and return + from the _source field + :arg analyze_wildcard: Specify whether wildcards and prefix + queries in the query string query should be analyzed (default: false) + :arg analyzer: The analyzer for the query string query + :arg default_operator: The default operator for query string + query (AND or OR) Valid choices: AND, OR Default: OR + :arg df: The default field for query string query (default: + _all) + :arg lenient: Specify whether format-based query failures (such + as providing text to a numeric field) should be ignored + :arg preference: Specify the node or shard the operation should + be performed on (default: random) + :arg q: Query in the Lucene query string syntax + :arg routing: Specific routing value + :arg stored_fields: A comma-separated list of stored fields to + return in the response + """ + for param in (index, id): + if param in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument.") + + return self.transport.perform_request( + "GET", _make_path(index, doc_type, id, "_explain"), params=params, body=body + ) + + @query_params( + "allow_no_indices", + "expand_wildcards", + "fields", + "ignore_unavailable", + "include_unmapped", + ) + def field_caps(self, index=None, params=None): + """ + Returns the information about the capabilities of fields among multiple + indices. + ``_ + + :arg index: A comma-separated list of index names; use `_all` or + empty string to perform the operation on all indices + :arg allow_no_indices: Whether to ignore if a wildcard indices + expression resolves into no concrete indices. (This includes `_all` + string or when no indices have been specified) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg fields: A comma-separated list of field names + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg include_unmapped: Indicates whether unmapped fields should + be included in the response. + """ + return self.transport.perform_request( + "GET", _make_path(index, "_field_caps"), params=params + ) + + @query_params( + "_source", + "_source_excludes", + "_source_includes", "preference", "realtime", "refresh", @@ -502,45 +943,65 @@ class Elasticsearch(object): "version", "version_type", ) - def get(self, index, id, doc_type="_doc", params=None): + def get(self, index, id, doc_type=None, params=None): """ - Get a typed JSON document from the index based on its id. - ``_ + Returns a document. + ``_ :arg index: The name of the index :arg id: The document ID - :arg _source: True or false to return the _source field or not, or a - list of fields to return - :arg _source_excludes: A list of fields to exclude from the returned - _source field - :arg _source_includes: A list of fields to extract and return from the - _source field - :arg parent: The ID of the parent document - :arg preference: Specify the node or shard the operation should be - performed on (default: random) - :arg realtime: Specify whether to perform the operation in realtime or - search mode + :arg doc_type: The type of the document (use `_all` to fetch the + first document matching the ID across all types) + :arg _source: True or false to return the _source field or not, + or a list of fields to return + :arg _source_excludes: A list of fields to exclude from the + returned _source field + :arg _source_includes: A list of fields to extract and return + from the _source field + :arg preference: Specify the node or shard the operation should + be performed on (default: random) + :arg realtime: Specify whether to perform the operation in + realtime or search mode :arg refresh: Refresh the shard containing the document before performing the operation :arg routing: Specific routing value - :arg stored_fields: A comma-separated list of stored fields to return in - the response + :arg stored_fields: A comma-separated list of stored fields to + return in the response :arg version: Explicit version number for concurrency control - :arg version_type: Specific version type, valid choices are: 'internal', - 'external', 'external_gte', 'force' + :arg version_type: Specific version type Valid choices: + internal, external, external_gte, force """ for param in (index, id): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + + if doc_type is None: + doc_type = "_doc" + return self.transport.perform_request( "GET", _make_path(index, doc_type, id), params=params ) + @query_params("master_timeout") + def get_script(self, id, params=None): + """ + Returns a script. + ``_ + + :arg id: Script ID + :arg master_timeout: Specify timeout for connection to master + """ + if id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'id'.") + + return self.transport.perform_request( + "GET", _make_path("_scripts", id), params=params + ) + @query_params( "_source", "_source_excludes", "_source_includes", - "parent", "preference", "realtime", "refresh", @@ -548,34 +1009,36 @@ class Elasticsearch(object): "version", "version_type", ) - def get_source(self, index, id, doc_type="_doc", params=None): + def get_source(self, index, id, doc_type=None, params=None): """ - Get the source of a document by it's index, type and id. - ``_ + Returns the source of a document. + ``_ :arg index: The name of the index :arg id: The document ID - :arg _source: True or false to return the _source field or not, or a - list of fields to return - :arg _source_excludes: A list of fields to exclude from the returned - _source field - :arg _source_includes: A list of fields to extract and return from the - _source field - :arg parent: The ID of the parent document - :arg preference: Specify the node or shard the operation should be - performed on (default: random) - :arg realtime: Specify whether to perform the operation in realtime or - search mode + :arg doc_type: The type of the document; deprecated and optional + starting with 7.0 + :arg _source: True or false to return the _source field or not, + or a list of fields to return + :arg _source_excludes: A list of fields to exclude from the + returned _source field + :arg _source_includes: A list of fields to extract and return + from the _source field + :arg preference: Specify the node or shard the operation should + be performed on (default: random) + :arg realtime: Specify whether to perform the operation in + realtime or search mode :arg refresh: Refresh the shard containing the document before performing the operation :arg routing: Specific routing value :arg version: Explicit version number for concurrency control - :arg version_type: Specific version type, valid choices are: 'internal', - 'external', 'external_gte', 'force' + :arg version_type: Specific version type Valid choices: + internal, external, external_gte, force """ for param in (index, id): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "GET", _make_path(index, doc_type, id, "_source"), params=params ) @@ -590,101 +1053,349 @@ class Elasticsearch(object): "routing", "stored_fields", ) - def mget(self, body, doc_type=None, index=None, params=None): + def mget(self, body, index=None, doc_type=None, params=None): """ - Get multiple documents based on an index, type (optional) and ids. - ``_ + Allows to get multiple documents in one request. + ``_ - :arg body: Document identifiers; can be either `docs` (containing full - document information) or `ids` (when index and type is provided in - the URL. + :arg body: Document identifiers; can be either `docs` + (containing full document information) or `ids` (when index and type is + provided in the URL. :arg index: The name of the index - :arg _source: True or false to return the _source field or not, or a - list of fields to return - :arg _source_excludes: A list of fields to exclude from the returned - _source field - :arg _source_includes: A list of fields to extract and return from the - _source field - :arg preference: Specify the node or shard the operation should be - performed on (default: random) - :arg realtime: Specify whether to perform the operation in realtime or - search mode + :arg doc_type: The type of the document + :arg _source: True or false to return the _source field or not, + or a list of fields to return + :arg _source_excludes: A list of fields to exclude from the + returned _source field + :arg _source_includes: A list of fields to extract and return + from the _source field + :arg preference: Specify the node or shard the operation should + be performed on (default: random) + :arg realtime: Specify whether to perform the operation in + realtime or search mode :arg refresh: Refresh the shard containing the document before performing the operation :arg routing: Specific routing value - :arg stored_fields: A comma-separated list of stored fields to return in - the response + :arg stored_fields: A comma-separated list of stored fields to + return in the response """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "GET", _make_path(index, doc_type, "_mget"), params=params, body=body ) @query_params( - "_source", - "_source_excludes", - "_source_includes", + "ccs_minimize_roundtrips", + "max_concurrent_searches", + "max_concurrent_shard_requests", + "pre_filter_shard_size", + "rest_total_hits_as_int", + "search_type", + "typed_keys", + ) + def msearch(self, body, index=None, doc_type=None, params=None): + """ + Allows to execute several search operations in one request. + ``_ + + :arg body: The request definitions (metadata-search request + definition pairs), separated by newlines + :arg index: A comma-separated list of index names to use as + default + :arg doc_type: A comma-separated list of document types to use + as default + :arg ccs_minimize_roundtrips: Indicates whether network round- + trips should be minimized as part of cross-cluster search requests + execution Default: true + :arg max_concurrent_searches: Controls the maximum number of + concurrent searches the multi search api will execute + :arg max_concurrent_shard_requests: The number of concurrent + shard requests each sub search executes concurrently per node. This + value should be used to limit the impact of the search on the cluster in + order to limit the number of concurrent shard requests Default: 5 + :arg pre_filter_shard_size: A threshold that enforces a pre- + filter roundtrip to prefilter search shards based on query rewriting if + the number of shards the search request expands to exceeds the + threshold. This filter roundtrip can limit the number of shards + significantly if for instance a shard can not match any documents based + on it's rewrite method ie. if date filters are mandatory to match but + the shard bounds and the query are disjoint. Default: 128 + :arg rest_total_hits_as_int: Indicates whether hits.total should + be rendered as an integer or an object in the rest search response + :arg search_type: Search operation type Valid choices: + query_then_fetch, query_and_fetch, dfs_query_then_fetch, + dfs_query_and_fetch + :arg typed_keys: Specify whether aggregation and suggester names + should be prefixed by their respective types in the response + """ + if body in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'body'.") + + body = self._bulk_body(body) + return self.transport.perform_request( + "GET", _make_path(index, doc_type, "_msearch"), params=params, body=body + ) + + @query_params( + "max_concurrent_searches", "rest_total_hits_as_int", "search_type", "typed_keys" + ) + def msearch_template(self, body, index=None, doc_type=None, params=None): + """ + Allows to execute several search template operations in one request. + ``_ + + :arg body: The request definitions (metadata-search request + definition pairs), separated by newlines + :arg index: A comma-separated list of index names to use as + default + :arg doc_type: A comma-separated list of document types to use + as default + :arg max_concurrent_searches: Controls the maximum number of + concurrent searches the multi search api will execute + :arg rest_total_hits_as_int: Indicates whether hits.total should + be rendered as an integer or an object in the rest search response + :arg search_type: Search operation type Valid choices: + query_then_fetch, query_and_fetch, dfs_query_then_fetch, + dfs_query_and_fetch + :arg typed_keys: Specify whether aggregation and suggester names + should be prefixed by their respective types in the response + """ + if body in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'body'.") + + body = self._bulk_body(body) + return self.transport.perform_request( + "GET", + _make_path(index, doc_type, "_msearch", "template"), + params=params, + body=body, + ) + + @query_params( + "field_statistics", "fields", - "if_seq_no", - "if_primary_term", - "lang", - "parent", - "refresh", - "retry_on_conflict", + "ids", + "offsets", + "payloads", + "positions", + "preference", + "realtime", "routing", - "timeout", - "timestamp", - "ttl", + "term_statistics", "version", "version_type", - "wait_for_active_shards", ) - def update(self, index, id, doc_type="_doc", body=None, params=None): + def mtermvectors(self, body=None, index=None, doc_type=None, params=None): """ - Update a document based on a script or partial data provided. - ``_ + Returns multiple termvectors in one request. + ``_ - :arg index: The name of the index - :arg id: Document ID - :arg body: The request definition using either `script` or partial `doc` - :arg _source: True or false to return the _source field or not, or a - list of fields to return - :arg _source_excludes: A list of fields to exclude from the returned - _source field - :arg _source_includes: A list of fields to extract and return from the - _source field - :arg fields: A comma-separated list of fields to return in the response - :arg if_seq_no: - :arg if_primary_term: - :arg lang: The script language (default: painless) - :arg parent: ID of the parent document. Is is only used for routing and - when for the upsert request - :arg refresh: If `true` then refresh the effected 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 do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' - :arg retry_on_conflict: Specify how many times should the operation be - retried when a conflict occurs (default: 0) - :arg routing: Specific routing value - :arg timeout: Explicit operation timeout - :arg timestamp: Explicit timestamp for the document - :arg ttl: Expiration time for the document + :arg body: Define ids, documents, parameters or a list of + parameters per document here. You must at least provide a list of + document ids. See documentation. + :arg index: The index in which the document resides. + :arg doc_type: The type of the document. + :arg field_statistics: Specifies if document count, sum of + document frequencies and sum of total term frequencies should be + returned. Applies to all returned documents unless otherwise specified + in body "params" or "docs". Default: True + :arg fields: A comma-separated list of fields to return. Applies + to all returned documents unless otherwise specified in body "params" or + "docs". + :arg ids: A comma-separated list of documents ids. You must + define ids as parameter or set "ids" or "docs" in the request body + :arg offsets: Specifies if term offsets should be returned. + Applies to all returned documents unless otherwise specified in body + "params" or "docs". Default: True + :arg payloads: Specifies if term payloads should be returned. + Applies to all returned documents unless otherwise specified in body + "params" or "docs". Default: True + :arg positions: Specifies if term positions should be returned. + Applies to all returned documents unless otherwise specified in body + "params" or "docs". Default: True + :arg preference: Specify the node or shard the operation should + be performed on (default: random) .Applies to all returned documents + unless otherwise specified in body "params" or "docs". + :arg realtime: Specifies if requests are real-time as opposed to + near-real-time (default: true). + :arg routing: Specific routing value. Applies to all returned + documents unless otherwise specified in body "params" or "docs". + :arg term_statistics: Specifies if total term frequency and + document frequency should be returned. Applies to all returned documents + unless otherwise specified in body "params" or "docs". :arg version: Explicit version number for concurrency control - :arg version_type: Specific version type, valid choices are: 'internal', - 'force' - :arg wait_for_active_shards: Sets the number of shard copies that must - be active before proceeding with the update operation. Defaults to - 1, meaning the primary shard only. Set to `all` for all shard - copies, otherwise set to any non-negative value less than or equal - to the total number of copies for the shard (number of replicas + 1) + :arg version_type: Specific version type Valid choices: + internal, external, external_gte, force """ - for param in (index, id): + return self.transport.perform_request( + "GET", + _make_path(index, doc_type, "_mtermvectors"), + params=params, + body=body, + ) + + @query_params("context", "master_timeout", "timeout") + def put_script(self, id, body, context=None, params=None): + """ + Creates or updates a script. + ``_ + + :arg id: Script ID + :arg body: The document + :arg context: Script context + :arg context: Context name to compile script against + :arg master_timeout: Specify timeout for connection to master + :arg timeout: Explicit operation timeout + """ + for param in (id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( - "POST", _make_path(index, doc_type, id, "_update"), params=params, body=body + "PUT", _make_path("_scripts", id, context), params=params, body=body + ) + + @query_params("allow_no_indices", "expand_wildcards", "ignore_unavailable") + def rank_eval(self, body, index=None, params=None): + """ + Allows to evaluate the quality of ranked search results over a set of typical + search queries + ``_ + + :arg body: The ranking evaluation search definition, including + search requests, document ratings and ranking metric definition. + :arg index: A comma-separated list of index names to search; use + `_all` or empty string to perform the operation on all indices + :arg allow_no_indices: Whether to ignore if a wildcard indices + expression resolves into no concrete indices. (This includes `_all` + string or when no indices have been specified) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + """ + if body in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'body'.") + + return self.transport.perform_request( + "GET", _make_path(index, "_rank_eval"), params=params, body=body + ) + + @query_params( + "max_docs", + "refresh", + "requests_per_second", + "scroll", + "slices", + "timeout", + "wait_for_active_shards", + "wait_for_completion", + ) + def reindex(self, body, params=None): + """ + Allows to copy documents from one index to another, optionally filtering the + source documents by a query, changing the destination index settings, or + fetching the documents from a remote cluster. + ``_ + + :arg body: The search definition using the Query DSL and the + prototype for the index request. + :arg max_docs: Maximum number of documents to process (default: + all documents) + :arg refresh: Should the effected indexes be refreshed? + :arg requests_per_second: The throttle to set on this request in + sub-requests per second. -1 means no throttle. + :arg scroll: Control how long to keep the search context alive + Default: 5m + :arg slices: The number of slices this task should be divided + into. Defaults to 1 meaning the task isn't sliced into subtasks. + Default: 1 + :arg timeout: Time each individual bulk request should wait for + shards that are unavailable. Default: 1m + :arg wait_for_active_shards: Sets the number of shard copies + that must be active before proceeding with the reindex operation. + Defaults to 1, meaning the primary shard only. Set to `all` for all + shard copies, otherwise set to any non-negative value less than or equal + to the total number of copies for the shard (number of replicas + 1) + :arg wait_for_completion: Should the request should block until + the reindex is complete. Default: True + """ + if body in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'body'.") + + return self.transport.perform_request( + "POST", "/_reindex", params=params, body=body + ) + + @query_params("requests_per_second") + def reindex_rethrottle(self, task_id, params=None): + """ + Changes the number of requests per second for a particular Reindex operation. + ``_ + + :arg task_id: The task id to rethrottle + :arg requests_per_second: The throttle to set on this request in + floating sub-requests per second. -1 means set no throttle. + """ + if task_id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'task_id'.") + + return self.transport.perform_request( + "POST", _make_path("_reindex", task_id, "_rethrottle"), params=params + ) + + @query_params() + def render_search_template(self, body=None, id=None, params=None): + """ + Allows to use the Mustache language to pre-render a search definition. + ``_ + + :arg body: The search definition template and its params + :arg id: The id of the stored search template + """ + return self.transport.perform_request( + "GET", _make_path("_render", "template", id), params=params, body=body + ) + + @query_params() + def scripts_painless_execute(self, body=None, params=None): + """ + Allows an arbitrary script to be executed and a result to be returned + ``_ + + :arg body: The script to execute + """ + return self.transport.perform_request( + "GET", "/_scripts/painless/_execute", params=params, body=body + ) + + @query_params("rest_total_hits_as_int", "scroll", "scroll_id") + def scroll(self, body=None, scroll_id=None, params=None): + """ + Allows to retrieve a large numbers of results from a single search request. + ``_ + + :arg body: The scroll ID if not passed by URL or query + parameter. + :arg scroll_id: The scroll ID + :arg rest_total_hits_as_int: Indicates whether hits.total should + be rendered as an integer or an object in the rest search response + :arg scroll: Specify how long a consistent view of the index + should be maintained for scrolled search + :arg scroll_id: The scroll ID for scrolled search + """ + if scroll_id in SKIP_IN_PATH and body in SKIP_IN_PATH: + raise ValueError("You need to supply scroll_id or body.") + elif scroll_id and not body: + body = {"scroll_id": scroll_id} + elif scroll_id: + params["scroll_id"] = scroll_id + + return self.transport.perform_request( + "GET", "/_search/scroll", params=params, body=body ) @query_params( @@ -710,8 +1421,8 @@ class Elasticsearch(object): "pre_filter_shard_size", "preference", "q", - "rest_total_hits_as_int", "request_cache", + "rest_total_hits_as_int", "routing", "scroll", "search_type", @@ -731,438 +1442,113 @@ class Elasticsearch(object): "typed_keys", "version", ) - def search(self, index=None, body=None, params=None): + def search(self, body=None, index=None, doc_type=None, params=None): """ - Execute a search query and get back search hits that match the query. - ``_ + Returns results matching a query. + ``_ - :arg index: A list of index names to search, or a string containing a - comma-separated list of index names to search; use `_all` - or empty string to perform the operation on all indices :arg body: The search definition using the Query DSL - :arg _source: True or false to return the _source field or not, or a - list of fields to return - :arg _source_excludes: A list of fields to exclude from the returned - _source field - :arg _source_includes: A list of fields to extract and return from the - _source field + :arg index: A comma-separated list of index names to search; use + `_all` or empty string to perform the operation on all indices + :arg doc_type: A comma-separated list of document types to + search; leave empty to perform the operation on all types + :arg _source: True or false to return the _source field or not, + or a list of fields to return + :arg _source_excludes: A list of fields to exclude from the + returned _source field + :arg _source_includes: A list of fields to extract and return + from the _source field :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg allow_partial_search_results: Set to false to return an overall - failure if the request would produce partial results. Defaults to - True, which will allow partial results in the case of timeouts or - partial failures - :arg analyze_wildcard: Specify whether wildcard and prefix queries - should be analyzed (default: false) + :arg allow_partial_search_results: Indicate if an error should + be returned if there is a partial search failure or timeout Default: + True + :arg analyze_wildcard: Specify whether wildcard and prefix + queries should be analyzed (default: false) :arg analyzer: The analyzer to use for the query string - :arg batched_reduce_size: The number of shard results that should be - reduced at once on the coordinating node. This value should be used - as a protection mechanism to reduce the memory overhead per search - request if the potential number of shards in the request can be - large., default 512 - :arg ccs_minimize_roundtrips: Indicates whether network round-trips - should be minimized as part of cross-cluster search requests - execution, default 'true' - :arg default_operator: The default operator for query string query (AND - or OR), default 'OR', valid choices are: 'AND', 'OR' - :arg df: The field to use as default where no field prefix is given in - the query string - :arg docvalue_fields: A comma-separated list of fields to return as the - docvalue representation of a field for each hit - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg explain: Specify whether to return detailed information about score - computation as part of a hit - :arg from\\_: Starting offset (default: 0) - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg lenient: Specify whether format-based query failures (such as - providing text to a numeric field) should be ignored - :arg max_concurrent_shard_requests: The number of concurrent shard - requests this search executes concurrently. This value should be - used to limit the impact of the search on the cluster in order to - limit the number of concurrent shard requests, default 'The default - grows with the number of nodes in the cluster but is at most 256.' - :arg pre_filter_shard_size: A threshold that enforces a pre-filter - roundtrip to prefilter search shards based on query rewriting if - the number of shards the search request expands to exceeds the + :arg batched_reduce_size: The number of shard results that + should be reduced at once on the coordinating node. This value should be + used as a protection mechanism to reduce the memory overhead per search + request if the potential number of shards in the request can be large. + Default: 512 + :arg ccs_minimize_roundtrips: Indicates whether network round- + trips should be minimized as part of cross-cluster search requests + execution Default: true + :arg default_operator: The default operator for query string + query (AND or OR) Valid choices: AND, OR Default: OR + :arg df: The field to use as default where no field prefix is + given in the query string + :arg docvalue_fields: A comma-separated list of fields to return + as the docvalue representation of a field for each hit + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg explain: Specify whether to return detailed information + about score computation as part of a hit + :arg from_: Starting offset (default: 0) + :arg ignore_throttled: Whether specified concrete, expanded or + aliased indices should be ignored when throttled + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg lenient: Specify whether format-based query failures (such + as providing text to a numeric field) should be ignored + :arg max_concurrent_shard_requests: The number of concurrent + shard requests per node this search executes concurrently. This value + should be used to limit the impact of the search on the cluster in order + to limit the number of concurrent shard requests Default: 5 + :arg pre_filter_shard_size: A threshold that enforces a pre- + filter roundtrip to prefilter search shards based on query rewriting if + the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards - significantly if for instance a shard can not match any documents - based on it's rewrite method ie. if date filters are mandatory to - match but the shard bounds and the query are disjoint., default 128 - :arg preference: Specify the node or shard the operation should be - performed on (default: random) + significantly if for instance a shard can not match any documents based + on it's rewrite method ie. if date filters are mandatory to match but + the shard bounds and the query are disjoint. Default: 128 + :arg preference: Specify the node or shard the operation should + be performed on (default: random) :arg q: Query in the Lucene query string syntax - :arg rest_total_hits_as_int: This parameter is used to restore the total hits as a number - in the response. This param is added version 6.x to handle mixed cluster queries where nodes - are in multiple versions (7.0 and 6.latest) - :arg request_cache: Specify if request cache should be used for this - request or not, defaults to index level setting + :arg request_cache: Specify if request cache should be used for + this request or not, defaults to index level setting + :arg rest_total_hits_as_int: Indicates whether hits.total should + be rendered as an integer or an object in the rest search response :arg routing: A comma-separated list of specific routing values - :arg scroll: Specify how long a consistent view of the index should be - maintained for scrolled search - :arg search_type: Search operation type, valid choices are: - 'query_then_fetch', 'dfs_query_then_fetch' + :arg scroll: Specify how long a consistent view of the index + should be maintained for scrolled search + :arg search_type: Search operation type Valid choices: + query_then_fetch, dfs_query_then_fetch + :arg seq_no_primary_term: Specify whether to return sequence + number and primary term of the last modification of each hit :arg size: Number of hits to return (default: 10) :arg sort: A comma-separated list of : pairs - :arg stats: Specific 'tag' of the request for logging and statistical - purposes - :arg stored_fields: A comma-separated list of stored fields to return as - part of a hit + :arg stats: Specific 'tag' of the request for logging and + statistical purposes + :arg stored_fields: A comma-separated list of stored fields to + return as part of a hit :arg suggest_field: Specify which field to use for suggestions - :arg suggest_mode: Specify suggest mode, default 'missing', valid - choices are: 'missing', 'popular', 'always' + :arg suggest_mode: Specify suggest mode Valid choices: missing, + popular, always Default: missing :arg suggest_size: How many suggestions to return in response - :arg suggest_text: The source text for which the suggestions should be - returned - :arg terminate_after: The maximum number of documents to collect for - each shard, upon reaching which the query execution will terminate + :arg suggest_text: The source text for which the suggestions + should be returned + :arg terminate_after: The maximum number of documents to collect + for each shard, upon reaching which the query execution will terminate early. :arg timeout: Explicit operation timeout - :arg track_scores: Whether to calculate and return scores even if they - are not used for sorting - :arg track_total_hits: Indicate if the number of documents that match - the query should be tracked - :arg typed_keys: Specify whether aggregation and suggester names should - be prefixed by their respective types in the response - :arg version: Specify whether to return document version as part of a - hit + :arg track_scores: Whether to calculate and return scores even + if they are not used for sorting + :arg track_total_hits: Indicate if the number of documents that + match the query should be tracked + :arg typed_keys: Specify whether aggregation and suggester names + should be prefixed by their respective types in the response + :arg version: Specify whether to return document version as part + of a hit """ # from is a reserved word so it cannot be used, use from_ instead if "from_" in params: params["from"] = params.pop("from_") - if not index: - index = "_all" return self.transport.perform_request( - "GET", _make_path(index, "_search"), params=params, body=body - ) - - @query_params( - "_source", - "_source_excludes", - "_source_includes", - "allow_no_indices", - "analyze_wildcard", - "analyzer", - "conflicts", - "default_operator", - "df", - "expand_wildcards", - "from_", - "ignore_unavailable", - "lenient", - "pipeline", - "preference", - "q", - "refresh", - "request_cache", - "requests_per_second", - "routing", - "scroll", - "scroll_size", - "search_timeout", - "search_type", - "size", - "slices", - "sort", - "stats", - "terminate_after", - "timeout", - "version", - "version_type", - "wait_for_active_shards", - "wait_for_completion", - ) - def update_by_query(self, index, body=None, params=None): - """ - Perform an update on all documents matching a query. - ``_ - - :arg index: A list of index names to search, or a string containing a - comma-separated list of index names to search; use `_all` or the - empty string to perform the operation on all indices - :arg body: The search definition using the Query DSL - :arg _source: True or false to return the _source field or not, or a - list of fields to return - :arg _source_excludes: A list of fields to exclude from the returned - _source field - :arg _source_includes: A list of fields to extract and return from the - _source field - :arg allow_no_indices: Whether to ignore if a wildcard indices - expression resolves into no concrete indices. (This includes `_all` - string or when no indices have been specified) - :arg analyze_wildcard: Specify whether wildcard and prefix queries - should be analyzed (default: false) - :arg analyzer: The analyzer to use for the query string - :arg conflicts: What to do when the update by query hits version - conflicts?, default 'abort', valid choices are: 'abort', 'proceed' - :arg default_operator: The default operator for query string query (AND - or OR), default 'OR', valid choices are: 'AND', 'OR' - :arg df: The field to use as default where no field prefix is given in - the query string - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg from\\_: Starting offset (default: 0) - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg lenient: Specify whether format-based query failures (such as - providing text to a numeric field) should be ignored - :arg pipeline: Ingest pipeline to set on index requests made by this - action. (default: none) - :arg preference: Specify the node or shard the operation should be - performed on (default: random) - :arg q: Query in the Lucene query string syntax - :arg refresh: Should the effected indexes be refreshed? - :arg request_cache: Specify if request cache should be used for this - request or not, defaults to index level setting - :arg requests_per_second: The throttle to set on this request in sub- - requests per second. -1 means no throttle., default 0 - :arg routing: A comma-separated list of specific routing values - :arg scroll: Specify how long a consistent view of the index should be - maintained for scrolled search - :arg scroll_size: Size on the scroll request powering the - update_by_query - :arg search_timeout: Explicit timeout for each search request. Defaults - to no timeout. - :arg search_type: Search operation type, valid choices are: - 'query_then_fetch', 'dfs_query_then_fetch' - :arg size: Number of hits to return (default: 10) - :arg slices: The number of slices this task should be divided into. - Defaults to 1 meaning the task isn't sliced into subtasks., default - 1 - :arg sort: A comma-separated list of : pairs - :arg stats: Specific 'tag' of the request for logging and statistical - purposes - :arg terminate_after: The maximum number of documents to collect for - each shard, upon reaching which the query execution will terminate - early. - :arg timeout: Time each individual bulk request should wait for shards - that are unavailable., default '1m' - :arg version: Specify whether to return document version as part of a - hit - :arg version_type: Should the document increment the version number - (internal) on hit or not (reindex) - :arg wait_for_active_shards: Sets the number of shard copies that must - be active before proceeding with the update by query operation. - Defaults to 1, meaning the primary shard only. Set to `all` for all - shard copies, otherwise set to any non-negative value less than or - equal to the total number of copies for the shard (number of - replicas + 1) - :arg wait_for_completion: Should the request should block until the - update by query operation is complete., default True - """ - if index in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'index'.") - return self.transport.perform_request( - "POST", _make_path(index, "_update_by_query"), params=params, body=body - ) - - @query_params("requests_per_second") - def update_by_query_rethrottle(self, task_id, params=None): - """ - ``_ - - :arg task_id: The task id to rethrottle - :arg requests_per_second: The throttle to set on this request in - floating sub-requests per second. -1 means set no throttle. - """ - if task_id in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'task_id'.") - return self.transport.perform_request( - "POST", - _make_path("_update_by_query", task_id, "_rethrottle"), - params=params, - ) - - @query_params( - "refresh", - "requests_per_second", - "slices", - "scroll", - "timeout", - "wait_for_active_shards", - "wait_for_completion", - ) - def reindex(self, body, params=None): - """ - Reindex all documents from one index to another. - ``_ - - :arg body: The search definition using the Query DSL and the prototype - for the index request. - :arg refresh: Should the effected indexes be refreshed? - :arg requests_per_second: The throttle to set on this request in sub- - requests per second. -1 means no throttle., default 0 - :arg slices: The number of slices this task should be divided into. - Defaults to 1 meaning the task isn't sliced into subtasks., default - 1 - :arg scroll: Control how long to keep the search context alive, default - '5m' - :arg timeout: Time each individual bulk request should wait for shards - that are unavailable., default '1m' - :arg wait_for_active_shards: Sets the number of shard copies that must - be active before proceeding with the reindex operation. Defaults to - 1, meaning the primary shard only. Set to `all` for all shard - copies, otherwise set to any non-negative value less than or equal - to the total number of copies for the shard (number of replicas + 1) - :arg wait_for_completion: Should the request should block until the - reindex is complete., default True - """ - if body in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'body'.") - return self.transport.perform_request( - "POST", "/_reindex", params=params, body=body - ) - - @query_params("requests_per_second") - def reindex_rethrottle(self, task_id=None, params=None): - """ - Change the value of ``requests_per_second`` of a running ``reindex`` task. - ``_ - - :arg task_id: The task id to rethrottle - :arg requests_per_second: The throttle to set on this request in - floating sub-requests per second. -1 means set no throttle. - """ - return self.transport.perform_request( - "POST", _make_path("_reindex", task_id, "_rethrottle"), params=params - ) - - @query_params( - "_source", - "_source_excludes", - "_source_includes", - "allow_no_indices", - "analyze_wildcard", - "analyzer", - "conflicts", - "default_operator", - "df", - "expand_wildcards", - "from_", - "ignore_unavailable", - "lenient", - "preference", - "q", - "refresh", - "request_cache", - "requests_per_second", - "routing", - "scroll", - "scroll_size", - "search_timeout", - "search_type", - "size", - "slices", - "sort", - "stats", - "terminate_after", - "timeout", - "version", - "wait_for_active_shards", - "wait_for_completion", - ) - def delete_by_query(self, index, body, params=None): - """ - Delete all documents matching a query. - ``_ - - :arg index: A list of index names to search, or a string containing a - comma-separated list of index names to search; use `_all` or the - empty string to perform the operation on all indices - :arg body: The search definition using the Query DSL - :arg _source: True or false to return the _source field or not, or a - list of fields to return - :arg _source_excludes: A list of fields to exclude from the returned - _source field - :arg _source_includes: A list of fields to extract and return from the - _source field - :arg allow_no_indices: Whether to ignore if a wildcard indices - expression resolves into no concrete indices. (This includes `_all` - string or when no indices have been specified) - :arg analyze_wildcard: Specify whether wildcard and prefix queries - should be analyzed (default: false) - :arg analyzer: The analyzer to use for the query string - :arg conflicts: What to do when the delete-by-query hits version - conflicts?, default 'abort', valid choices are: 'abort', 'proceed' - :arg default_operator: The default operator for query string query (AND - or OR), default 'OR', valid choices are: 'AND', 'OR' - :arg df: The field to use as default where no field prefix is given in - the query string - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg from\\_: Starting offset (default: 0) - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg lenient: Specify whether format-based query failures (such as - providing text to a numeric field) should be ignored - :arg preference: Specify the node or shard the operation should be - performed on (default: random) - :arg q: Query in the Lucene query string syntax - :arg refresh: Should the effected indexes be refreshed? - :arg request_cache: Specify if request cache should be used for this - request or not, defaults to index level setting - :arg requests_per_second: The throttle for this request in sub-requests - per second. -1 means no throttle., default 0 - :arg routing: A comma-separated list of specific routing values - :arg scroll: Specify how long a consistent view of the index should be - maintained for scrolled search - :arg scroll_size: Size on the scroll request powering the - update_by_query - :arg search_timeout: Explicit timeout for each search request. Defaults - to no timeout. - :arg search_type: Search operation type, valid choices are: - 'query_then_fetch', 'dfs_query_then_fetch' - :arg size: Number of hits to return (default: 10) - :arg slices: The number of slices this task should be divided into. - Defaults to 1 meaning the task isn't sliced into subtasks., default - 1 - :arg sort: A comma-separated list of : pairs - :arg stats: Specific 'tag' of the request for logging and statistical - purposes - :arg terminate_after: The maximum number of documents to collect for - each shard, upon reaching which the query execution will terminate - early. - :arg timeout: Time each individual bulk request should wait for shards - that are unavailable., default '1m' - :arg version: Specify whether to return document version as part of a - hit - :arg wait_for_active_shards: Sets the number of shard copies that must - be active before proceeding with the delete by query operation. - Defaults to 1, meaning the primary shard only. Set to `all` for all - shard copies, otherwise set to any non-negative value less than or - equal to the total number of copies for the shard (number of - replicas + 1) - :arg wait_for_completion: Should the request should block until the - delete-by-query is complete., default True - """ - for param in (index, body): - if param in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument.") - return self.transport.perform_request( - "POST", _make_path(index, "_delete_by_query"), params=params, body=body - ) - - @query_params("requests_per_second") - def delete_by_query_rethrottle(self, task_id, params=None): - """ - ``_ - - :arg task_id: The task id to rethrottle - :arg requests_per_second: The throttle to set on this request in - floating sub-requests per second. -1 means set no throttle. - """ - if task_id in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'task_id'.") - return self.transport.perform_request( - "POST", - _make_path("_delete_by_query", task_id, "_rethrottle"), - params=params, + "GET", _make_path(index, doc_type, "_search"), params=params, body=body ) @query_params( @@ -1175,26 +1561,24 @@ class Elasticsearch(object): ) def search_shards(self, index=None, params=None): """ - The search shards api returns the indices and shards that a search - request would be executed against. This can give useful feedback for working - out issues or planning optimizations with routing and shard preferences. - ``_ + Returns information about the indices and shards that a search request would be + executed against. + ``_ - :arg index: A list of index names to search, or a string containing a - comma-separated list of index names to search; use `_all` or the - empty string to perform the operation on all indices + :arg index: A comma-separated list of index names to search; use + `_all` or empty string to perform the operation on all indices :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg preference: Specify the node or shard the operation should be - performed on (default: random) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg preference: Specify the node or shard the operation should + be performed on (default: random) :arg routing: Specific routing value """ return self.transport.perform_request( @@ -1203,372 +1587,68 @@ class Elasticsearch(object): @query_params( "allow_no_indices", - "ccs_minimize_roundtrips", "expand_wildcards", "explain", + "ignore_throttled", "ignore_unavailable", "preference", "profile", - "routing", "rest_total_hits_as_int", + "routing", "scroll", "search_type", "typed_keys", ) - def search_template(self, index=None, body=None, params=None): + def search_template(self, body, index=None, doc_type=None, params=None): """ - A query that accepts a query template and a map of key/value pairs to - fill in template parameters. - ``_ + Allows to use the Mustache language to pre-render a search definition. + ``_ - :arg index: A list of index names to search, or a string containing a - comma-separated list of index names to search; use `_all` or the - empty string to perform the operation on all indices :arg body: The search definition template and its params + :arg index: A comma-separated list of index names to search; use + `_all` or empty string to perform the operation on all indices + :arg doc_type: A comma-separated list of document types to + search; leave empty to perform the operation on all types :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg ccs_minimize_roundtrips: Indicates whether network round-trips - should be minimized as part of cross-cluster search requests - execution, default 'true' - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg explain: Specify whether to return detailed information about score - computation as part of a hit - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg preference: Specify the node or shard the operation should be - performed on (default: random) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg explain: Specify whether to return detailed information + about score computation as part of a hit + :arg ignore_throttled: Whether specified concrete, expanded or + aliased indices should be ignored when throttled + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg preference: Specify the node or shard the operation should + be performed on (default: random) :arg profile: Specify whether to profile the query execution + :arg rest_total_hits_as_int: Indicates whether hits.total should + be rendered as an integer or an object in the rest search response :arg routing: A comma-separated list of specific routing values - :arg rest_total_hits_as_int: Indicates whether hits.total should be - rendered as an integer or an object in the rest search response, - default False - :arg scroll: Specify how long a consistent view of the index should be - maintained for scrolled search - :arg search_type: Search operation type, valid choices are: - 'query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch', - 'dfs_query_and_fetch' - :arg typed_keys: Specify whether aggregation and suggester names should - be prefixed by their respective types in the response - """ - return self.transport.perform_request( - "GET", _make_path(index, "_search", "template"), params=params, body=body - ) - - @query_params( - "_source", - "_source_excludes", - "_source_includes", - "analyze_wildcard", - "analyzer", - "default_operator", - "df", - "lenient", - "parent", - "preference", - "q", - "routing", - "stored_fields", - ) - def explain(self, index, id, doc_type="_doc", body=None, params=None): - """ - The explain api computes a score explanation for a query and a specific - document. This can give useful feedback whether a document matches or - didn't match a specific query. - ``_ - - :arg index: The name of the index - :arg id: The document ID - :arg body: The query definition using the Query DSL - :arg _source: True or false to return the _source field or not, or a - list of fields to return - :arg _source_excludes: A list of fields to exclude from the returned - _source field - :arg _source_includes: A list of fields to extract and return from the - _source field - :arg analyze_wildcard: Specify whether wildcards and prefix queries in - the query string query should be analyzed (default: false) - :arg analyzer: The analyzer for the query string query - :arg default_operator: The default operator for query string query (AND - or OR), default 'OR', valid choices are: 'AND', 'OR' - :arg df: The default field for query string query (default: _all) - :arg lenient: Specify whether format-based query failures (such as - providing text to a numeric field) should be ignored - :arg parent: The ID of the parent document - :arg preference: Specify the node or shard the operation should be - performed on (default: random) - :arg q: Query in the Lucene query string syntax - :arg routing: Specific routing value - :arg stored_fields: A comma-separated list of stored fields to return in - the response - """ - for param in (index, id): - if param in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument.") - return self.transport.perform_request( - "GET", _make_path(index, doc_type, id, "_explain"), params=params, body=body - ) - - @query_params("scroll", "rest_total_hits_as_int") - def scroll(self, body=None, scroll_id=None, params=None): - """ - Scroll a search request created by specifying the scroll parameter. - ``_ - - :arg scroll_id: The scroll ID - :arg body: The scroll ID if not passed by URL or query parameter. - :arg scroll: Specify how long a consistent view of the index should be - maintained for scrolled search - :arg rest_total_hits_as_int: This parameter is used to restore the total hits as a number - in the response. This param is added version 6.x to handle mixed cluster queries where nodes - are in multiple versions (7.0 and 6.latest) - """ - if scroll_id in SKIP_IN_PATH and body in SKIP_IN_PATH: - raise ValueError("You need to supply scroll_id or body.") - elif scroll_id and not body: - body = {"scroll_id": scroll_id} - elif scroll_id: - params["scroll_id"] = scroll_id - - return self.transport.perform_request( - "GET", "/_search/scroll", params=params, body=body - ) - - @query_params() - def clear_scroll(self, scroll_id=None, body=None, params=None): - """ - Clear the scroll request created by specifying the scroll parameter to - search. - ``_ - - :arg scroll_id: A comma-separated list of scroll IDs to clear - :arg body: A comma-separated list of scroll IDs to clear if none was - specified via the scroll_id parameter - """ - if scroll_id in SKIP_IN_PATH and body in SKIP_IN_PATH: - raise ValueError("You need to supply scroll_id or body.") - elif scroll_id and not body: - body = {"scroll_id": [scroll_id]} - elif scroll_id: - params["scroll_id"] = scroll_id - - return self.transport.perform_request( - "DELETE", "/_search/scroll", params=params, body=body - ) - - @query_params( - "if_seq_no", - "if_primary_term", - "parent", - "refresh", - "routing", - "timeout", - "version", - "version_type", - "wait_for_active_shards", - ) - def delete(self, index, id, doc_type="_doc", params=None): - """ - Delete a typed JSON document from a specific index based on its id. - ``_ - - :arg index: The name of the index - :arg id: The document ID - :arg if_primary_term: only perform the delete operation if the last - operation that has changed the document has the specified primary - term - :arg if_seq_no: only perform the delete operation if the last operation - that has changed the document has the specified sequence number - :arg parent: ID of parent document - :arg refresh: If `true` then refresh the effected 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 do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' - :arg routing: Specific routing value - :arg timeout: Explicit operation timeout - :arg version: Explicit version number for concurrency control - :arg version_type: Specific version type, valid choices are: 'internal', - 'external', 'external_gte', 'force' - :arg wait_for_active_shards: Sets the number of shard copies that must - be active before proceeding with the delete operation. Defaults to - 1, meaning the primary shard only. Set to `all` for all shard - copies, otherwise set to any non-negative value less than or equal - to the total number of copies for the shard (number of replicas + 1) - """ - for param in (index, id): - if param in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument.") - return self.transport.perform_request( - "DELETE", _make_path(index, doc_type, id), params=params - ) - - @query_params( - "allow_no_indices", - "analyze_wildcard", - "analyzer", - "default_operator", - "df", - "expand_wildcards", - "ignore_unavailable", - "ignore_throttled", - "lenient", - "min_score", - "preference", - "q", - "routing", - "terminate_after", - ) - def count(self, doc_type=None, index=None, body=None, params=None): - """ - Execute a query and get the number of matches for that query. - ``_ - - :arg index: A list of index names or a string containing a - comma-separated list of index names to restrict the results to - :arg body: A query to restrict the results specified with the Query DSL - (optional) - :arg allow_no_indices: Whether to ignore if a wildcard indices - expression resolves into no concrete indices. (This includes `_all` - string or when no indices have been specified) - :arg analyze_wildcard: Specify whether wildcard and prefix queries - should be analyzed (default: false) - :arg analyzer: The analyzer to use for the query string - :arg default_operator: The default operator for query string query (AND - or OR), default 'OR', valid choices are: 'AND', 'OR' - :arg df: The field to use as default where no field prefix is given in - the query string - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg ignore_throttled: Whether specified concrete, expanded or aliased - indices should be ignored when throttled - :arg lenient: Specify whether format-based query failures (such as - providing text to a numeric field) should be ignored - :arg min_score: Include only documents with a specific `_score` value in - the result - :arg preference: Specify the node or shard the operation should be - performed on (default: random) - :arg q: Query in the Lucene query string syntax - :arg routing: Specific routing value - """ - if not index: - index = "_all" - - return self.transport.perform_request( - "GET", _make_path(index, doc_type, "_count"), params=params, body=body - ) - - @query_params( - "_source", - "_source_excludes", - "_source_includes", - "fields", - "pipeline", - "refresh", - "routing", - "timeout", - "wait_for_active_shards", - ) - def bulk(self, body, doc_type=None, index=None, params=None): - """ - Perform many index/delete operations in a single API call. - - See the :func:`~elasticsearch.helpers.bulk` helper function for a more - friendly API. - ``_ - - :arg body: The operation definition and data (action-data pairs), - separated by newlines - :arg index: Default index for items which don't provide one - :arg _source: True or false to return the _source field or not, or - default list of fields to return, can be overridden on each sub- - request - :arg _source_excludes: Default list of fields to exclude from the - returned _source field, can be overridden on each sub-request - :arg _source_includes: Default list of fields to extract and return from - the _source field, can be overridden on each sub-request - :arg fields: Default comma-separated list of fields to return in the - response for updates, can be overridden on each sub-request - :arg pipeline: The pipeline id to preprocess incoming documents with - :arg refresh: If `true` then refresh the effected 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 do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' - :arg routing: Specific routing value - :arg timeout: Explicit operation timeout - :arg wait_for_active_shards: Sets the number of shard copies that must - be active before proceeding with the bulk operation. Defaults to 1, - meaning the primary shard only. Set to `all` for all shard copies, - otherwise set to any non-negative value less than or equal to the - total number of copies for the shard (number of replicas + 1) + :arg scroll: Specify how long a consistent view of the index + should be maintained for scrolled search + :arg search_type: Search operation type Valid choices: + query_then_fetch, query_and_fetch, dfs_query_then_fetch, + dfs_query_and_fetch + :arg typed_keys: Specify whether aggregation and suggester names + should be prefixed by their respective types in the response """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") - return self.transport.perform_request( - "POST", - _make_path(index, doc_type, "_bulk"), - params=params, - body=self._bulk_body(body), - headers={"content-type": "application/x-ndjson"}, - ) - @query_params( - "ccs_minimize_roundtrips", - "max_concurrent_searches", - "max_concurrent_shard_requests", - "pre_filter_shard_size", - "rest_total_hits_as_int", - "search_type", - "typed_keys", - ) - def msearch(self, body, index=None, params=None): - """ - Execute several search requests within the same API. - ``_ - - :arg body: The request definitions (metadata-search request definition - pairs), separated by newlines - :arg index: A list of index names, or a string containing a - comma-separated list of index names, to use as the default - :arg ccs_minimize_roundtrips: Indicates whether network round-trips - should be minimized as part of cross-cluster search requests - execution, default 'true' - :arg max_concurrent_searches: Controls the maximum number of concurrent - searches the multi search api will execute - :arg pre_filter_shard_size: A threshold that enforces a pre-filter - roundtrip to prefilter search shards based on query rewriting if - the number of shards the search request expands to exceeds the - threshold. This filter roundtrip can limit the number of shards - significantly if for instance a shard can not match any documents - based on it's rewrite method ie. if date filters are mandatory to - match but the shard bounds and the query are disjoint., default 128 - :arg search_type: Search operation type, valid choices are: - 'query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch', - 'dfs_query_and_fetch' - :arg typed_keys: Specify whether aggregation and suggester names should - be prefixed by their respective types in the response - """ - if body in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'body'.") return self.transport.perform_request( "GET", - _make_path(index, "_msearch"), + _make_path(index, doc_type, "_search", "template"), params=params, - body=self._bulk_body(body), - headers={"content-type": "application/x-ndjson"}, + body=body, ) @query_params( "field_statistics", "fields", "offsets", - "parent", "payloads", "positions", "preference", @@ -1578,45 +1658,42 @@ class Elasticsearch(object): "version", "version_type", ) - def termvectors(self, index, doc_type="_doc", id=None, body=None, params=None): + def termvectors(self, index, body=None, doc_type=None, id=None, params=None): """ - Returns information and statistics on terms in the fields of a - particular document. The document could be stored in the index or - artificially provided by the user (Added in 1.4). Note that for - documents stored in the index, this is a near realtime API as the term - vectors are not available until the next refresh. - ``_ + Returns information and statistics about terms in the fields of a particular + document. + ``_ :arg index: The index in which the document resides. - :arg id: The id of the document, when not specified a doc param should - be supplied. - :arg body: Define parameters and or supply a document to get termvectors - for. See documentation. - :arg field_statistics: Specifies if document count, sum of document - frequencies and sum of total term frequencies should be returned., - default True + :arg body: Define parameters and or supply a document to get + termvectors for. See documentation. + :arg doc_type: The type of the document. + :arg id: The id of the document, when not specified a doc param + should be supplied. + :arg field_statistics: Specifies if document count, sum of + document frequencies and sum of total term frequencies should be + returned. Default: True :arg fields: A comma-separated list of fields to return. - :arg offsets: Specifies if term offsets should be returned., default - True - :arg parent: Parent id of documents. - :arg payloads: Specifies if term payloads should be returned., default - True - :arg positions: Specifies if term positions should be returned., default - True - :arg preference: Specify the node or shard the operation should be - performed on (default: random). - :arg realtime: Specifies if request is real-time as opposed to near- - real-time (default: true). + :arg offsets: Specifies if term offsets should be returned. + Default: True + :arg payloads: Specifies if term payloads should be returned. + Default: True + :arg positions: Specifies if term positions should be returned. + Default: True + :arg preference: Specify the node or shard the operation should + be performed on (default: random). + :arg realtime: Specifies if request is real-time as opposed to + near-real-time (default: true). :arg routing: Specific routing value. - :arg term_statistics: Specifies if total term frequency and document - frequency should be returned., default False + :arg term_statistics: Specifies if total term frequency and + document frequency should be returned. :arg version: Explicit version number for concurrency control - :arg version_type: Specific version type, valid choices are: 'internal', - 'external', 'external_gte', 'force' + :arg version_type: Specific version type Valid choices: + internal, external, external_gte, force """ - for param in (index,): - if param in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument.") + if index in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "GET", _make_path(index, doc_type, id, "_termvectors"), @@ -1625,245 +1702,213 @@ class Elasticsearch(object): ) @query_params( - "field_statistics", - "fields", - "ids", - "offsets", - "parent", - "payloads", - "positions", - "preference", - "realtime", + "_source", + "_source_excludes", + "_source_includes", + "if_primary_term", + "if_seq_no", + "lang", + "refresh", + "retry_on_conflict", "routing", - "term_statistics", + "timeout", + "wait_for_active_shards", + ) + def update(self, index, id, body, doc_type=None, params=None): + """ + Updates a document with a script or partial document. + ``_ + + :arg index: The name of the index + :arg id: Document ID + :arg body: The request definition requires either `script` or + partial `doc` + :arg doc_type: The type of the document + :arg _source: True or false to return the _source field or not, + or a list of fields to return + :arg _source_excludes: A list of fields to exclude from the + returned _source field + :arg _source_includes: A list of fields to extract and return + from the _source field + :arg if_primary_term: only perform the update operation if the + last operation that has changed the document has the specified primary + term + :arg if_seq_no: only perform the update operation if the last + operation that has changed the document has the specified sequence + number + :arg lang: The script language (default: painless) + :arg refresh: If `true` then refresh the effected 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 + do nothing with refreshes. Valid choices: true, false, wait_for + :arg retry_on_conflict: Specify how many times should the + operation be retried when a conflict occurs (default: 0) + :arg routing: Specific routing value + :arg timeout: Explicit operation timeout + :arg wait_for_active_shards: Sets the number of shard copies + that must be active before proceeding with the update operation. + Defaults to 1, meaning the primary shard only. Set to `all` for all + shard copies, otherwise set to any non-negative value less than or equal + to the total number of copies for the shard (number of replicas + 1) + """ + for param in (index, id, body): + if param in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument.") + + return self.transport.perform_request( + "POST", _make_path(index, doc_type, id, "_update"), params=params, body=body + ) + + @query_params( + "_source", + "_source_excludes", + "_source_includes", + "allow_no_indices", + "analyze_wildcard", + "analyzer", + "conflicts", + "default_operator", + "df", + "expand_wildcards", + "from_", + "ignore_unavailable", + "lenient", + "max_docs", + "pipeline", + "preference", + "q", + "refresh", + "request_cache", + "requests_per_second", + "routing", + "scroll", + "scroll_size", + "search_timeout", + "search_type", + "size", + "slices", + "sort", + "stats", + "terminate_after", + "timeout", "version", "version_type", + "wait_for_active_shards", + "wait_for_completion", ) - def mtermvectors(self, doc_type=None, index=None, body=None, params=None): + def update_by_query(self, index, body=None, doc_type=None, params=None): """ - Multi termvectors API allows to get multiple termvectors based on an - index, type and id. - ``_ + Performs an update on every document in the index without changing the source, + for example to pick up a mapping change. + ``_ - :arg index: The index in which the document resides. - :arg body: Define ids, documents, parameters or a list of parameters per - document here. You must at least provide a list of document ids. See - documentation. - :arg field_statistics: Specifies if document count, sum of document - frequencies and sum of total term frequencies should be returned. - Applies to all returned documents unless otherwise specified in body - "params" or "docs"., default True - :arg fields: A comma-separated list of fields to return. Applies to all - returned documents unless otherwise specified in body "params" or - "docs". - :arg ids: A comma-separated list of documents ids. You must define ids - as parameter or set "ids" or "docs" in the request body - :arg offsets: Specifies if term offsets should be returned. Applies to - all returned documents unless otherwise specified in body "params" - or "docs"., default True - :arg parent: Parent id of documents. Applies to all returned documents - unless otherwise specified in body "params" or "docs". - :arg payloads: Specifies if term payloads should be returned. Applies to - all returned documents unless otherwise specified in body "params" - or "docs"., default True - :arg positions: Specifies if term positions should be returned. Applies - to all returned documents unless otherwise specified in body - "params" or "docs"., default True - :arg preference: Specify the node or shard the operation should be - performed on (default: random) .Applies to all returned documents - unless otherwise specified in body "params" or "docs". - :arg realtime: Specifies if requests are real-time as opposed to near- - real-time (default: true). - :arg routing: Specific routing value. Applies to all returned documents - unless otherwise specified in body "params" or "docs". - :arg term_statistics: Specifies if total term frequency and document - frequency should be returned. Applies to all returned documents - unless otherwise specified in body "params" or "docs"., default - False - :arg version: Explicit version number for concurrency control - :arg version_type: Specific version type, valid choices are: 'internal', - 'external', 'external_gte', 'force' + :arg index: A comma-separated list of index names to search; use + `_all` or empty string to perform the operation on all indices + :arg body: The search definition using the Query DSL + :arg doc_type: A comma-separated list of document types to + search; leave empty to perform the operation on all types + :arg _source: True or false to return the _source field or not, + or a list of fields to return + :arg _source_excludes: A list of fields to exclude from the + returned _source field + :arg _source_includes: A list of fields to extract and return + from the _source field + :arg allow_no_indices: Whether to ignore if a wildcard indices + expression resolves into no concrete indices. (This includes `_all` + string or when no indices have been specified) + :arg analyze_wildcard: Specify whether wildcard and prefix + queries should be analyzed (default: false) + :arg analyzer: The analyzer to use for the query string + :arg conflicts: What to do when the update by query hits version + conflicts? Valid choices: abort, proceed Default: abort + :arg default_operator: The default operator for query string + query (AND or OR) Valid choices: AND, OR Default: OR + :arg df: The field to use as default where no field prefix is + given in the query string + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg from_: Starting offset (default: 0) + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg lenient: Specify whether format-based query failures (such + as providing text to a numeric field) should be ignored + :arg max_docs: Maximum number of documents to process (default: + all documents) + :arg pipeline: Ingest pipeline to set on index requests made by + this action. (default: none) + :arg preference: Specify the node or shard the operation should + be performed on (default: random) + :arg q: Query in the Lucene query string syntax + :arg refresh: Should the effected indexes be refreshed? + :arg request_cache: Specify if request cache should be used for + this request or not, defaults to index level setting + :arg requests_per_second: The throttle to set on this request in + sub-requests per second. -1 means no throttle. + :arg routing: A comma-separated list of specific routing values + :arg scroll: Specify how long a consistent view of the index + should be maintained for scrolled search + :arg scroll_size: Size on the scroll request powering the update + by query + :arg search_timeout: Explicit timeout for each search request. + Defaults to no timeout. + :arg search_type: Search operation type Valid choices: + query_then_fetch, dfs_query_then_fetch + :arg size: Deprecated, please use `max_docs` instead + :arg slices: The number of slices this task should be divided + into. Defaults to 1 meaning the task isn't sliced into subtasks. + Default: 1 + :arg sort: A comma-separated list of : pairs + :arg stats: Specific 'tag' of the request for logging and + statistical purposes + :arg terminate_after: The maximum number of documents to collect + for each shard, upon reaching which the query execution will terminate + early. + :arg timeout: Time each individual bulk request should wait for + shards that are unavailable. Default: 1m + :arg version: Specify whether to return document version as part + of a hit + :arg version_type: Should the document increment the version + number (internal) on hit or not (reindex) + :arg wait_for_active_shards: Sets the number of shard copies + that must be active before proceeding with the update by query + operation. Defaults to 1, meaning the primary shard only. Set to `all` + for all shard copies, otherwise set to any non-negative value less than + or equal to the total number of copies for the shard (number of replicas + + 1) + :arg wait_for_completion: Should the request should block until + the update by query operation is complete. Default: True """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + + if index in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( - "GET", - _make_path(index, doc_type, "_mtermvectors"), + "POST", + _make_path(index, doc_type, "_update_by_query"), params=params, body=body, ) - @query_params("master_timeout", "timeout") - def put_script(self, id, body, context=None, params=None): + @query_params("requests_per_second") + def update_by_query_rethrottle(self, task_id, params=None): """ - Create a script in given language with specified ID. - ``_ + Changes the number of requests per second for a particular Update By Query + operation. + ``_ + + :arg task_id: The task id to rethrottle + :arg requests_per_second: The throttle to set on this request in + floating sub-requests per second. -1 means set no throttle. + """ + if task_id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'task_id'.") - :arg id: Script ID - :arg body: The document - :arg master_timeout: Specify timeout for connection to master - :arg timeout: Explicit operation timeout - """ - for param in (id, body): - if param in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument.") return self.transport.perform_request( - "PUT", _make_path("_scripts", id, context), params=params, body=body - ) - - @query_params("allow_no_indices", "expand_wildcards", "ignore_unavailable") - def rank_eval(self, body, index=None, params=None): - """ - ``_ - - :arg body: The ranking evaluation search definition, including search - requests, document ratings and ranking metric definition. - :arg index: A comma-separated list of index names to search; use `_all` - or empty string to perform the operation on all indices - :arg allow_no_indices: Whether to ignore if a wildcard indices - expression resolves into no concrete indices. (This includes `_all` - string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - """ - if body in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'body'.") - return self.transport.perform_request( - "GET", _make_path(index, "_rank_eval"), params=params, body=body - ) - - @query_params("master_timeout") - def get_script(self, id, params=None): - """ - Retrieve a script from the API. - ``_ - - :arg id: Script ID - :arg master_timeout: Specify timeout for connection to master - """ - if id in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'id'.") - return self.transport.perform_request( - "GET", _make_path("_scripts", id), params=params - ) - - @query_params("master_timeout", "timeout") - def delete_script(self, id, params=None): - """ - Remove a stored script from elasticsearch. - ``_ - - :arg id: Script ID - :arg master_timeout: Specify timeout for connection to master - :arg timeout: Explicit operation timeout """ - if id in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'id'.") - return self.transport.perform_request( - "DELETE", _make_path("_scripts", id), params=params - ) - - @query_params() - def render_search_template(self, id=None, body=None, params=None): - """ - ``_ - - :arg id: The id of the stored search template - :arg body: The search definition template and its params - """ - return self.transport.perform_request( - "GET", _make_path("_render", "template", id), params=params, body=body - ) - - @query_params("context") - def scripts_painless_context(self, params=None): - """ - `<>`_ - - :arg context: Select a specific context to retrieve API information - about - """ - return self.transport.perform_request( - "GET", "/_scripts/painless/_context", params=params - ) - - @query_params() - def scripts_painless_execute(self, body=None, params=None): - """ - ``_ - - :arg body: The script to execute - """ - return self.transport.perform_request( - "GET", "/_scripts/painless/_execute", params=params, body=body - ) - - @query_params( - "ccs_minimize_roundtrips", - "max_concurrent_searches", - "search_type", - "typed_keys", - ) - def msearch_template(self, body, index=None, params=None): - """ - The /_search/template endpoint allows to use the mustache language to - pre render search requests, before they are executed and fill existing - templates with template parameters. - ``_ - - :arg body: The request definitions (metadata-search request definition - pairs), separated by newlines - :arg index: A list of index names, or a string containing a - comma-separated list of index names, to use as the default - :arg ccs_minimize_roundtrips: Indicates whether network round-trips - should be minimized as part of cross-cluster search requests - execution, default 'true' - :arg max_concurrent_searches: Controls the maximum number of concurrent - searches the multi search api will execute - :arg search_type: Search operation type, valid choices are: - 'query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch', - 'dfs_query_and_fetch' - :arg typed_keys: Specify whether aggregation and suggester names should - be prefixed by their respective types in the response - """ - if body in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'body'.") - return self.transport.perform_request( - "GET", - _make_path(index, "_msearch", "template"), + "POST", + _make_path("_update_by_query", task_id, "_rethrottle"), params=params, - body=self._bulk_body(body), - headers={"content-type": "application/x-ndjson"}, - ) - - @query_params( - "allow_no_indices", - "expand_wildcards", - "fields", - "ignore_unavailable", - "include_unmapped", - ) - def field_caps(self, index=None, body=None, params=None): - """ - The field capabilities API allows to retrieve the capabilities of fields among multiple indices. - ``_ - - :arg index: A list of index names, or a string containing a - comma-separated list of index names; use `_all` or the empty string - to perform the operation on all indices - :arg body: Field json objects containing an array of field names - :arg allow_no_indices: Whether to ignore if a wildcard indices - expression resolves into no concrete indices. (This includes `_all` - string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg fields: A comma-separated list of field names - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg include_unmapped: Indicates whether unmapped fields should be - included in the response., default False - """ - return self.transport.perform_request( - "GET", _make_path(index, "_field_caps"), params=params, body=body ) diff --git a/elasticsearch/client/cat.py b/elasticsearch/client/cat.py index 46ac8e8b..515483e4 100644 --- a/elasticsearch/client/cat.py +++ b/elasticsearch/client/cat.py @@ -2,23 +2,23 @@ from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH class CatClient(NamespacedClient): - @query_params("format", "h", "help", "local", "master_timeout", "s", "v") + @query_params("format", "h", "help", "local", "s", "v") def aliases(self, name=None, params=None): """ - - ``_ + Shows information about currently configured aliases to indices including + filter and routing infos. + ``_ :arg name: A comma-separated list of alias names to return - :arg format: a short version of the Accept header, e.g. json, yaml + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request( "GET", _make_path("_cat", "aliases", name), params=params @@ -27,123 +27,128 @@ class CatClient(NamespacedClient): @query_params("bytes", "format", "h", "help", "local", "master_timeout", "s", "v") def allocation(self, node_id=None, params=None): """ - Allocation provides a snapshot of how shards have located around the - cluster and the state of disk usage. - ``_ + Provides a snapshot of how many shards are allocated to each data node and how + much disk space they are using. + ``_ - :arg node_id: A comma-separated list of node IDs or names to limit the - returned information - :arg bytes: The unit in which to display byte values, valid choices are: - 'b', 'k', 'kb', 'm', 'mb', 'g', 'gb', 't', 'tb', 'p', 'pb' - :arg format: a short version of the Accept header, e.g. json, yaml + :arg node_id: A comma-separated list of node IDs or names to + limit the returned information + :arg bytes: The unit in which to display byte values Valid + choices: b, k, kb, m, mb, g, gb, t, tb, p, pb + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request( "GET", _make_path("_cat", "allocation", node_id), params=params ) - @query_params("format", "h", "help", "local", "master_timeout", "s", "v") + @query_params("format", "h", "help", "s", "v") def count(self, index=None, params=None): """ - Count provides quick access to the document count of the entire cluster, - or individual indices. - ``_ + Provides quick access to the document count of the entire cluster, or + individual indices. + ``_ - :arg index: A comma-separated list of index names to limit the returned - information - :arg format: a short version of the Accept header, e.g. json, yaml + :arg index: A comma-separated list of index names to limit the + returned information + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request( "GET", _make_path("_cat", "count", index), params=params ) - @query_params("format", "h", "help", "local", "master_timeout", "s", "ts", "v") + @query_params("format", "h", "help", "s", "time", "ts", "v") def health(self, params=None): """ - health is a terse, one-line representation of the same information from - :meth:`~elasticsearch.client.cluster.ClusterClient.health` API - ``_ + Returns a concise representation of the cluster health. + ``_ - :arg format: a short version of the Accept header, e.g. json, yaml + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg ts: Set to false to disable timestamping, default True - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg time: The unit in which to display time values Valid + choices: d (Days), h (Hours), m (Minutes), s (Seconds), ms + (Milliseconds), micros (Microseconds), nanos (Nanoseconds) + :arg ts: Set to false to disable timestamping Default: True + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request("GET", "/_cat/health", params=params) @query_params("help", "s") def help(self, params=None): """ - A simple help for the cat api. - ``_ + Returns help for the Cat APIs. + ``_ - :arg help: Return help information, default False - :arg s: Comma-separated list of column names or column aliases to sort - by + :arg help: Return help information + :arg s: Comma-separated list of column names or column aliases + to sort by """ return self.transport.perform_request("GET", "/_cat", params=params) @query_params( "bytes", - "size", "format", "h", "health", "help", + "include_unloaded_segments", "local", "master_timeout", "pri", "s", + "time", "v", ) def indices(self, index=None, params=None): """ - The indices command provides a cross-section of each index. - ``_ + Returns information about indices: number of primaries and replicas, document + counts, disk size, ... + ``_ - :arg index: A comma-separated list of index names to limit the returned - information - :arg bytes: The unit in which to display byte values, valid choices are: - 'b', 'k', 'm', 'g' - :arg format: a short version of the Accept header, e.g. json, yaml + :arg index: A comma-separated list of index names to limit the + returned information + :arg bytes: The unit in which to display byte values Valid + choices: b, k, m, g + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg health: A health status ("green", "yellow", or "red" to filter only - indices matching the specified health status, default None, valid - choices are: 'green', 'yellow', 'red' - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg pri: Set to true to return stats only for primary shards, default - False - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg health: A health status ("green", "yellow", or "red" to + filter only indices matching the specified health status Valid choices: + green, yellow, red + :arg help: Return help information + :arg include_unloaded_segments: If set to true segment stats + will include stats for segments that are not currently loaded into + memory + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg pri: Set to true to return stats only for primary shards + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg time: The unit in which to display time values Valid + choices: d (Days), h (Hours), m (Minutes), s (Seconds), ms + (Milliseconds), micros (Microseconds), nanos (Nanoseconds) + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request( "GET", _make_path("_cat", "indices", index), params=params @@ -152,134 +157,176 @@ class CatClient(NamespacedClient): @query_params("format", "h", "help", "local", "master_timeout", "s", "v") def master(self, params=None): """ - Displays the master's node ID, bound IP address, and node name. - ``_ + Returns information about the master node. + ``_ - :arg format: a short version of the Accept header, e.g. json, yaml + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request("GET", "/_cat/master", params=params) - @query_params("format", "full_id", "h", "help", "local", "master_timeout", "s", "v") + @query_params( + "bytes", + "format", + "full_id", + "h", + "help", + "local", + "master_timeout", + "s", + "time", + "v", + ) def nodes(self, params=None): """ - The nodes command shows the cluster topology. - ``_ + Returns basic statistics about performance of cluster nodes. + ``_ - :arg format: a short version of the Accept header, e.g. json, yaml - :arg full_id: Return the full node ID instead of the shortened version - (default: false) + :arg bytes: The unit in which to display byte values Valid + choices: b, k, kb, m, mb, g, gb, t, tb, p, pb + :arg format: a short version of the Accept header, e.g. json, + yaml + :arg full_id: Return the full node ID instead of the shortened + version (default: false) :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg time: The unit in which to display time values Valid + choices: d (Days), h (Hours), m (Minutes), s (Seconds), ms + (Milliseconds), micros (Microseconds), nanos (Nanoseconds) + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request("GET", "/_cat/nodes", params=params) @query_params( - "bytes", "time", "size", "format", "h", "help", "master_timeout", "s", "v" + "active_only", + "bytes", + "detailed", + "format", + "h", + "help", + "index", + "s", + "time", + "v", ) def recovery(self, index=None, params=None): """ - recovery is a view of shard replication. - ``_ + Returns information about index shard recoveries, both on-going completed. + ``_ - :arg index: A comma-separated list of index names to limit the returned - information - :arg bytes: The unit in which to display byte values, valid choices are: - 'b', 'k', 'kb', 'm', 'mb', 'g', 'gb', 't', 'tb', 'p', 'pb' - :arg format: a short version of the Accept header, e.g. json, yaml + :arg index: Comma-separated list or wildcard expression of index + names to limit the returned information + :arg active_only: If `true`, the response only includes ongoing + shard recoveries + :arg bytes: The unit in which to display byte values Valid + choices: b, k, kb, m, mb, g, gb, t, tb, p, pb + :arg detailed: If `true`, the response includes detailed + information about shard recoveries + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg index: Comma-separated list or wildcard expression of index + names to limit the returned information + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg time: The unit in which to display time values Valid + choices: d (Days), h (Hours), m (Minutes), s (Seconds), ms + (Milliseconds), micros (Microseconds), nanos (Nanoseconds) + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request( "GET", _make_path("_cat", "recovery", index), params=params ) @query_params( - "bytes", "size", "format", "h", "help", "local", "master_timeout", "s", "v" + "bytes", "format", "h", "help", "local", "master_timeout", "s", "time", "v" ) def shards(self, index=None, params=None): """ - The shards command is the detailed view of what nodes contain which shards. - ``_ + Provides a detailed view of shard allocation on nodes. + ``_ - :arg index: A comma-separated list of index names to limit the returned - information - :arg bytes: The unit in which to display byte values, valid choices are: - 'b', 'k', 'kb', 'm', 'mb', 'g', 'gb', 't', 'tb', 'p', 'pb' - :arg format: a short version of the Accept header, e.g. json, yaml + :arg index: A comma-separated list of index names to limit the + returned information + :arg bytes: The unit in which to display byte values Valid + choices: b, k, kb, m, mb, g, gb, t, tb, p, pb + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg time: The unit in which to display time values Valid + choices: d (Days), h (Hours), m (Minutes), s (Seconds), ms + (Milliseconds), micros (Microseconds), nanos (Nanoseconds) + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request( "GET", _make_path("_cat", "shards", index), params=params ) - @query_params("bytes", "size", "format", "h", "help", "s", "v") + @query_params("bytes", "format", "h", "help", "s", "v") def segments(self, index=None, params=None): """ - The segments command is the detailed view of Lucene segments per index. - ``_ + Provides low-level information about the segments in the shards of an index. + ``_ - :arg index: A comma-separated list of index names to limit the returned - information - :arg bytes: The unit in which to display byte values, valid choices are: - 'b', 'k', 'kb', 'm', 'mb', 'g', 'gb', 't', 'tb', 'p', 'pb' - :arg format: a short version of the Accept header, e.g. json, yaml + :arg index: A comma-separated list of index names to limit the + returned information + :arg bytes: The unit in which to display byte values Valid + choices: b, k, kb, m, mb, g, gb, t, tb, p, pb + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request( "GET", _make_path("_cat", "segments", index), params=params ) - @query_params("format", "h", "help", "local", "master_timeout", "s", "v") + @query_params("format", "h", "help", "local", "master_timeout", "s", "time", "v") def pending_tasks(self, params=None): """ - pending_tasks provides the same information as the - :meth:`~elasticsearch.client.cluster.ClusterClient.pending_tasks` API - in a convenient tabular format. - ``_ + Returns a concise representation of the cluster pending tasks. + ``_ - :arg format: a short version of the Accept header, e.g. json, yaml + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg time: The unit in which to display time values Valid + choices: d (Days), h (Hours), m (Minutes), s (Seconds), ms + (Milliseconds), micros (Microseconds), nanos (Nanoseconds) + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request( "GET", "/_cat/pending_tasks", params=params @@ -288,23 +335,25 @@ class CatClient(NamespacedClient): @query_params("format", "h", "help", "local", "master_timeout", "s", "size", "v") def thread_pool(self, thread_pool_patterns=None, params=None): """ - Get information about thread pools. - ``_ + Returns cluster-wide thread pool statistics per node. By default the active, + queue and rejected statistics are returned for all thread pools. + ``_ - :arg thread_pool_patterns: A comma-separated list of regular-expressions - to filter the thread pools in the output - :arg format: a short version of the Accept header, e.g. json, yaml + :arg thread_pool_patterns: A comma-separated list of regular- + expressions to filter the thread pools in the output + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection 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 are: - '', 'k', 'm', 'g', 't', 'p' - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + 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 v: Verbose mode. Display column headers """ return self.transport.perform_request( "GET", @@ -312,26 +361,26 @@ class CatClient(NamespacedClient): params=params, ) - @query_params("bytes", "format", "h", "help", "local", "master_timeout", "s", "v") + @query_params("bytes", "fields", "format", "h", "help", "s", "v") def fielddata(self, fields=None, params=None): """ - Shows information about currently loaded fielddata on a per-node basis. - ``_ + Shows how much heap memory is currently being used by fielddata on every data + node in the cluster. + ``_ - :arg fields: A comma-separated list of fields to return the fielddata - size - :arg bytes: The unit in which to display byte values, valid choices are: - 'b', 'k', 'kb', 'm', 'mb', 'g', 'gb', 't', 'tb', 'p', 'pb' - :arg format: a short version of the Accept header, e.g. json, yaml + :arg fields: A comma-separated list of fields to return the + fielddata size + :arg bytes: The unit in which to display byte values Valid + choices: b, k, kb, m, mb, g, gb, t, tb, p, pb + :arg fields: A comma-separated list of fields to return in the + output + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request( "GET", _make_path("_cat", "fielddata", fields), params=params @@ -340,85 +389,90 @@ class CatClient(NamespacedClient): @query_params("format", "h", "help", "local", "master_timeout", "s", "v") def plugins(self, params=None): """ + Returns information about installed plugins across nodes node. + ``_ - ``_ - - :arg format: a short version of the Accept header, e.g. json, yaml + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request("GET", "/_cat/plugins", params=params) @query_params("format", "h", "help", "local", "master_timeout", "s", "v") def nodeattrs(self, params=None): """ + Returns information about custom node attributes. + ``_ - ``_ - - :arg format: a short version of the Accept header, e.g. json, yaml + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request("GET", "/_cat/nodeattrs", params=params) @query_params("format", "h", "help", "local", "master_timeout", "s", "v") def repositories(self, params=None): """ + Returns information about snapshot repositories registered in the cluster. + ``_ - ``_ - - :arg format: a short version of the Accept header, e.g. json, yaml + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node, default False - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg local: Return local information, do not retrieve the state + from master node + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request( "GET", "/_cat/repositories", params=params ) @query_params( - "format", "h", "help", "ignore_unavailable", "master_timeout", "s", "v" + "format", "h", "help", "ignore_unavailable", "master_timeout", "s", "time", "v" ) - def snapshots(self, repository, params=None): + def snapshots(self, repository=None, params=None): """ + Returns all snapshots in a specific repository. + ``_ - ``_ - - :arg repository: Name of repository from which to fetch the snapshot - information - :arg format: a short version of the Accept header, e.g. json, yaml + :arg repository: Name of repository from which to fetch the + snapshot information + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg ignore_unavailable: Set to true to ignore unavailable snapshots, - default False - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg ignore_unavailable: Set to true to ignore unavailable + snapshots + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg time: The unit in which to display time values Valid + choices: d (Days), h (Hours), m (Minutes), s (Seconds), ms + (Milliseconds), micros (Microseconds), nanos (Nanoseconds) + :arg v: Verbose mode. Display column headers """ - if repository in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'repository'.") return self.transport.perform_request( "GET", _make_path("_cat", "snapshots", repository), params=params ) @@ -429,55 +483,58 @@ class CatClient(NamespacedClient): "format", "h", "help", - "nodes", "node_id", - "parent_task_id", + "parent_task", "s", + "time", "v", ) def tasks(self, params=None): """ + Returns information about the tasks currently executing on one or more nodes in + the cluster. + ``_ - ``_ - - :arg actions: A comma-separated list of actions that should be returned. - Leave empty to return all. + :arg actions: A comma-separated list of actions that should be + returned. Leave empty to return all. :arg detailed: Return detailed task information (default: false) - :arg format: a short version of the Accept header, e.g. json, yaml + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg nodes: A comma-separated list of node IDs or names to limit the - returned information; use `_local` to return information from the - node you're connecting to, leave empty to get information from all - nodes (used for older version of Elasticsearch) - :arg node_id: A comma-separated list of node IDs or names to limit the - returned information; use `_local` to return information from the - node you're connecting to, leave empty to get information from all + :arg help: Return help information + :arg node_id: A comma-separated list of node IDs or names to + limit the returned information; use `_local` to return information from + the node you're connecting to, leave empty to get information from all nodes - :arg parent_task_id: Return tasks with specified parent task id. Set to -1 - to return all. - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg parent_task: Return tasks with specified parent task id. + Set to -1 to return all. + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg time: The unit in which to display time values Valid + choices: d (Days), h (Hours), m (Minutes), s (Seconds), ms + (Milliseconds), micros (Microseconds), nanos (Nanoseconds) + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request("GET", "/_cat/tasks", params=params) @query_params("format", "h", "help", "local", "master_timeout", "s", "v") def templates(self, name=None, params=None): """ - ``_ + Returns information about existing templates. + ``_ :arg name: A pattern that returned template names must match - :arg format: a short version of the Accept header, e.g. json, yaml + :arg format: a short version of the Accept header, e.g. json, + yaml :arg h: Comma-separated list of column names to display - :arg help: Return help information, default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg s: Comma-separated list of column names or column aliases to sort - by - :arg v: Verbose mode. Display column headers, default False + :arg help: Return help information + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg s: Comma-separated list of column names or column aliases + to sort by + :arg v: Verbose mode. Display column headers """ return self.transport.perform_request( "GET", _make_path("_cat", "templates", name), params=params diff --git a/elasticsearch/client/ccr.py b/elasticsearch/client/ccr.py index 469e556f..9796eb5a 100644 --- a/elasticsearch/client/ccr.py +++ b/elasticsearch/client/ccr.py @@ -11,6 +11,7 @@ class CcrClient(NamespacedClient): """ if name in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'name'.") + return self.transport.perform_request( "DELETE", _make_path("_ccr", "auto_follow", name), params=params ) @@ -21,29 +22,33 @@ class CcrClient(NamespacedClient): ``_ :arg index: The name of the follower index - :arg body: The name of the leader index and other optional ccr related - parameters - :arg wait_for_active_shards: Sets the number of shard copies that must - be active before returning. Defaults to 0. Set to `all` for all - shard copies, otherwise set to any non-negative value less than or - equal to the total number of copies for the shard (number of - replicas + 1), default '0' + :arg body: The name of the leader index and other optional ccr + related parameters + :arg wait_for_active_shards: Sets the number of shard copies + that must be active before returning. Defaults to 0. Set to `all` for + all shard copies, otherwise set to any non-negative value less than or + equal to the total number of copies for the shard (number of replicas + + 1) Default: 0 """ for param in (index, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path(index, "_ccr", "follow"), params=params, body=body ) @query_params() - def follow_info(self, index=None, params=None): + def follow_info(self, index, params=None): """ ``_ - :arg index: A comma-separated list of index patterns; use `_all` to - perform the operation on all indices + :arg index: A comma-separated list of index patterns; use `_all` + to perform the operation on all indices """ + if index in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "GET", _make_path(index, "_ccr", "info"), params=params ) @@ -53,11 +58,12 @@ class CcrClient(NamespacedClient): """ ``_ - :arg index: A comma-separated list of index patterns; use `_all` to - perform the operation on all indices + :arg index: A comma-separated list of index patterns; use `_all` + to perform the operation on all indices """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "GET", _make_path(index, "_ccr", "stats"), params=params ) @@ -67,16 +73,17 @@ class CcrClient(NamespacedClient): """ ``_ - :arg index: the name of the leader index for which specified follower - retention leases should be removed - :arg body: the name and UUID of the follower index, the name of the - cluster containing the follower index, and the alias from the - perspective of that cluster for the remote cluster containing the - leader index + :arg index: the name of the leader index for which specified + follower retention leases should be removed + :arg body: the name and UUID of the follower index, the name of + the cluster containing the follower index, and the alias from the + perspective of that cluster for the remote cluster containing the leader + index """ for param in (index, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "POST", _make_path(index, "_ccr", "forget_follower"), @@ -100,11 +107,12 @@ class CcrClient(NamespacedClient): """ ``_ - :arg index: The name of the follower index that should pause following - its leader index. + :arg index: The name of the follower index that should pause + following its leader index. """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "POST", _make_path(index, "_ccr", "pause_follow"), params=params ) @@ -120,6 +128,7 @@ class CcrClient(NamespacedClient): for param in (name, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_ccr", "auto_follow", name), params=params, body=body ) @@ -130,11 +139,12 @@ class CcrClient(NamespacedClient): ``_ :arg index: The name of the follow index to resume following. - :arg body: The name of the leader index and other optional ccr related - parameters + :arg body: The name of the leader index and other optional ccr + related parameters """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "POST", _make_path(index, "_ccr", "resume_follow"), params=params, body=body ) @@ -143,6 +153,7 @@ class CcrClient(NamespacedClient): def stats(self, params=None): """ ``_ + """ return self.transport.perform_request("GET", "/_ccr/stats", params=params) @@ -151,11 +162,42 @@ class CcrClient(NamespacedClient): """ ``_ - :arg index: The name of the follower index that should be turned into a - regular index. + :arg index: The name of the follower index that should be turned + into a regular index. """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "POST", _make_path(index, "_ccr", "unfollow"), params=params ) + + @query_params() + def pause_auto_follow_pattern(self, name, params=None): + """ + ``_ + + :arg name: The name of the auto follow pattern that should pause + discovering new indices to follow. + """ + if name in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'name'.") + + return self.transport.perform_request( + "POST", _make_path("_ccr", "auto_follow", name, "pause"), params=params + ) + + @query_params() + def resume_auto_follow_pattern(self, name, params=None): + """ + ``_ + + :arg name: The name of the auto follow pattern to resume + discovering new indices to follow. + """ + if name in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'name'.") + + return self.transport.perform_request( + "POST", _make_path("_ccr", "auto_follow", name, "resume"), params=params + ) diff --git a/elasticsearch/client/cluster.py b/elasticsearch/client/cluster.py index cd186bae..1a869748 100644 --- a/elasticsearch/client/cluster.py +++ b/elasticsearch/client/cluster.py @@ -17,31 +17,33 @@ class ClusterClient(NamespacedClient): ) def health(self, index=None, params=None): """ - Get a very simple status on the health of the cluster. - ``_ + Returns basic information about the health of the cluster. + ``_ :arg index: Limit the information returned to a specific index - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'all', valid choices - are: 'open', 'closed', 'none', 'all' - :arg level: Specify the level of detail for returned information, - default 'cluster', valid choices are: 'cluster', 'indices', 'shards' - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: all + :arg level: Specify the level of detail for returned information + Valid choices: cluster, indices, shards Default: cluster + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node :arg timeout: Explicit operation timeout - :arg wait_for_active_shards: Wait until the specified number of shards - is active - :arg wait_for_events: Wait until all currently queued events with the - given priority are processed, valid choices are: 'immediate', - 'urgent', 'high', 'normal', 'low', 'languid' - :arg wait_for_no_relocating_shards: Whether to wait until there are no - relocating shards in the cluster + :arg wait_for_active_shards: Wait until the specified number of + shards is active + :arg wait_for_events: Wait until all currently queued events + with the given priority are processed Valid choices: immediate, urgent, + high, normal, low, languid + :arg wait_for_no_initializing_shards: Whether to wait until + there are no initializing shards in the cluster + :arg wait_for_no_relocating_shards: Whether to wait until there + are no relocating shards in the cluster :arg wait_for_nodes: Wait until the specified number of nodes is available - :arg wait_for_status: Wait until cluster is in a specific state, default - None, valid choices are: 'green', 'yellow', 'red' + :arg wait_for_status: Wait until cluster is in a specific state + Valid choices: green, yellow, red """ return self.transport.perform_request( "GET", _make_path("_cluster", "health", index), params=params @@ -50,13 +52,12 @@ class ClusterClient(NamespacedClient): @query_params("local", "master_timeout") def pending_tasks(self, params=None): """ - The pending cluster tasks API returns a list of any cluster-level - changes (e.g. create index, update mapping, allocate or fail shard) - which have not yet been executed. - ``_ + Returns a list of any cluster-level changes (e.g. create index, update mapping, + allocate or fail shard) which have not yet been executed. + ``_ - :arg local: Return local information, do not retrieve the state from - master node (default: false) + :arg local: Return local information, do not retrieve the state + from master node (default: false) :arg master_timeout: Specify timeout for connection to master """ return self.transport.perform_request( @@ -75,31 +76,32 @@ class ClusterClient(NamespacedClient): ) def state(self, metric=None, index=None, params=None): """ - Get a comprehensive state information of the whole cluster. - ``_ + Returns a comprehensive information about the state of the cluster. + ``_ - :arg metric: Limit the information returned to the specified metrics - :arg index: A comma-separated list of index names; use `_all` or empty - string to perform the operation on all indices + :arg metric: Limit the information returned to the specified + metrics Valid choices: _all, blocks, metadata, nodes, routing_table, + routing_nodes, master_node, version + :arg index: A comma-separated list of index names; use `_all` or + empty string to perform the operation on all indices :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg flat_settings: Return settings in flat format (default: false) - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg local: Return local information, do not retrieve the state from - master node (default: false) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg flat_settings: Return settings in flat format (default: + false) + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg local: Return local information, do not retrieve the state + from master node (default: false) :arg master_timeout: Specify timeout for connection to master - :arg wait_for_metadata_version: Wait for the metadata version to be - equal or greater than the specified metadata version + :arg wait_for_metadata_version: Wait for the metadata version to + be equal or greater than the specified metadata version :arg wait_for_timeout: The maximum time to wait for wait_for_metadata_version before timing out """ - if index and not metric: - metric = "_all" return self.transport.perform_request( "GET", _make_path("_cluster", "state", metric, index), params=params ) @@ -107,44 +109,42 @@ class ClusterClient(NamespacedClient): @query_params("flat_settings", "timeout") def stats(self, node_id=None, params=None): """ - The Cluster Stats API allows to retrieve statistics from a cluster wide - perspective. The API returns basic index metrics and information about - the current nodes that form the cluster. - ``_ + Returns high-level overview of cluster statistics. + ``_ - :arg node_id: A comma-separated list of node IDs or names to limit the - returned information; use `_local` to return information from the - node you're connecting to, `_master` to return information from the - currently-elected master node or leave empty to get information from all + :arg node_id: A comma-separated list of node IDs or names to + limit the returned information; use `_local` to return information from + the node you're connecting to, leave empty to get information from all nodes - :arg flat_settings: Return settings in flat format (default: false) + :arg flat_settings: Return settings in flat format (default: + false) :arg timeout: Explicit operation timeout """ - url = "/_cluster/stats" - if node_id: - url = _make_path("_cluster", "stats", "nodes", node_id) - return self.transport.perform_request("GET", url, params=params) + return self.transport.perform_request( + "GET", _make_path("_cluster", "stats", "nodes", node_id), params=params + ) @query_params( "dry_run", "explain", "master_timeout", "metric", "retry_failed", "timeout" ) def reroute(self, body=None, params=None): """ - Explicitly execute a cluster reroute allocation command including specific commands. - ``_ + Allows to manually change the allocation of individual shards in the cluster. + ``_ - :arg body: The definition of `commands` to perform (`move`, `cancel`, - `allocate`) - :arg dry_run: Simulate the operation only and return the resulting state - :arg explain: Return an explanation of why the commands can or cannot be - executed - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg metric: Limit the information returned to the specified metrics. - Defaults to all but metadata, valid choices are: '_all', 'blocks', - 'metadata', 'nodes', 'routing_table', 'master_node', 'version' - :arg retry_failed: Retries allocation of shards that are blocked due to - too many subsequent allocation failures + :arg body: The definition of `commands` to perform (`move`, + `cancel`, `allocate`) + :arg dry_run: Simulate the operation only and return the + resulting state + :arg explain: Return an explanation of why the commands can or + cannot be executed + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg metric: Limit the information returned to the specified + metrics. Defaults to all but metadata Valid choices: _all, blocks, + metadata, nodes, routing_table, master_node, version + :arg retry_failed: Retries allocation of shards that are blocked + due to too many subsequent allocation failures :arg timeout: Explicit operation timeout """ return self.transport.perform_request( @@ -154,14 +154,15 @@ class ClusterClient(NamespacedClient): @query_params("flat_settings", "include_defaults", "master_timeout", "timeout") def get_settings(self, params=None): """ - Get cluster settings. - ``_ + Returns cluster settings. + ``_ - :arg flat_settings: Return settings in flat format (default: false) - :arg include_defaults: Whether to return all default clusters setting., - default False - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg flat_settings: Return settings in flat format (default: + false) + :arg include_defaults: Whether to return all default clusters + setting. + :arg master_timeout: Explicit operation timeout for connection + to master node :arg timeout: Explicit operation timeout """ return self.transport.perform_request( @@ -169,18 +170,22 @@ class ClusterClient(NamespacedClient): ) @query_params("flat_settings", "master_timeout", "timeout") - def put_settings(self, body=None, params=None): + def put_settings(self, body, params=None): """ - Update cluster wide specific settings. - ``_ + Updates the cluster settings. + ``_ - :arg body: The settings to be updated. Can be either `transient` or - `persistent` (survives cluster restart). - :arg flat_settings: Return settings in flat format (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg body: The settings to be updated. Can be either `transient` + or `persistent` (survives cluster restart). + :arg flat_settings: Return settings in flat format (default: + false) + :arg master_timeout: Explicit operation timeout for connection + to master node :arg timeout: Explicit operation timeout """ + if body in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "PUT", "/_cluster/settings", params=params, body=body ) @@ -188,21 +193,24 @@ class ClusterClient(NamespacedClient): @query_params() def remote_info(self, params=None): """ - ``_ + Returns the information about configured remote clusters. + ``_ + """ return self.transport.perform_request("GET", "/_remote/info", params=params) @query_params("include_disk_info", "include_yes_decisions") def allocation_explain(self, body=None, params=None): """ - ``_ + Provides explanations for shard allocations in the cluster. + ``_ - :arg body: The index, shard, and primary flag to explain. Empty means - 'explain the first unassigned shard' - :arg include_disk_info: Return information about disk usage and shard - sizes (default: false) - :arg include_yes_decisions: Return 'YES' decisions in explanation - (default: false) + :arg body: The index, shard, and primary flag to explain. Empty + means 'explain the first unassigned shard' + :arg include_disk_info: Return information about disk usage and + shard sizes (default: false) + :arg include_yes_decisions: Return 'YES' decisions in + explanation (default: false) """ return self.transport.perform_request( "GET", "/_cluster/allocation/explain", params=params, body=body diff --git a/elasticsearch/client/enrich.py b/elasticsearch/client/enrich.py new file mode 100644 index 00000000..d2952437 --- /dev/null +++ b/elasticsearch/client/enrich.py @@ -0,0 +1,68 @@ +from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH + + +class EnrichClient(NamespacedClient): + @query_params() + def delete_policy(self, name, params=None): + """ + ``_ + + :arg name: The name of the enrich policy + """ + if name in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'name'.") + + return self.transport.perform_request( + "DELETE", _make_path("_enrich", "policy", name), params=params + ) + + @query_params("wait_for_completion") + def execute_policy(self, name, params=None): + """ + ``_ + + :arg name: The name of the enrich policy + :arg wait_for_completion: Should the request should block until + the execution is complete. Default: True + """ + if name in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'name'.") + + return self.transport.perform_request( + "PUT", _make_path("_enrich", "policy", name, "_execute"), params=params + ) + + @query_params() + def get_policy(self, name=None, params=None): + """ + ``_ + + :arg name: The name of the enrich policy + """ + return self.transport.perform_request( + "GET", _make_path("_enrich", "policy", name), params=params + ) + + @query_params() + def put_policy(self, name, body, params=None): + """ + ``_ + + :arg name: The name of the enrich policy + :arg body: The enrich policy to register + """ + for param in (name, body): + if param in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument.") + + return self.transport.perform_request( + "PUT", _make_path("_enrich", "policy", name), params=params, body=body + ) + + @query_params() + def stats(self, params=None): + """ + ``_ + + """ + return self.transport.perform_request("GET", "/_enrich/_stats", params=params) diff --git a/elasticsearch/client/graph.py b/elasticsearch/client/graph.py index 2d438b5e..cf8f57b0 100644 --- a/elasticsearch/client/graph.py +++ b/elasticsearch/client/graph.py @@ -3,18 +3,21 @@ from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH class GraphClient(NamespacedClient): @query_params("routing", "timeout") - def explore(self, index=None, doc_type=None, body=None, params=None): + def explore(self, index, body=None, doc_type=None, params=None): """ ``_ - :arg index: A comma-separated list of index names to search; use `_all` - or empty string to perform the operation on all indices - :arg doc_type: A comma-separated list of document types to search; leave - empty to perform the operation on all types + :arg index: A comma-separated list of index names to search; use + `_all` or empty string to perform the operation on all indices :arg body: Graph Query DSL + :arg doc_type: A comma-separated list of document types to + search; leave empty to perform the operation on all types :arg routing: Specific routing value :arg timeout: Explicit operation timeout """ + if index in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "GET", _make_path(index, doc_type, "_graph", "explore"), diff --git a/elasticsearch/client/ilm.py b/elasticsearch/client/ilm.py index 6b3938bc..142a343c 100644 --- a/elasticsearch/client/ilm.py +++ b/elasticsearch/client/ilm.py @@ -3,23 +3,33 @@ from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH class IlmClient(NamespacedClient): @query_params() - def delete_lifecycle(self, policy=None, params=None): + def delete_lifecycle(self, policy, params=None): """ ``_ :arg policy: The name of the index lifecycle policy """ + if policy in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'policy'.") + return self.transport.perform_request( "DELETE", _make_path("_ilm", "policy", policy), params=params ) - @query_params() - def explain_lifecycle(self, index=None, params=None): + @query_params("only_errors", "only_managed") + def explain_lifecycle(self, index, params=None): """ ``_ :arg index: The name of the index to explain + :arg only_errors: filters the indices included in the response + to ones in an ILM error state, implies only_managed + :arg only_managed: filters the indices included in the response + to ones managed by ILM """ + if index in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "GET", _make_path(index, "_ilm", "explain"), params=params ) @@ -39,52 +49,66 @@ class IlmClient(NamespacedClient): def get_status(self, params=None): """ ``_ + """ return self.transport.perform_request("GET", "/_ilm/status", params=params) @query_params() - def move_to_step(self, index=None, body=None, params=None): + def move_to_step(self, index, body=None, params=None): """ ``_ - :arg index: The name of the index whose lifecycle step is to change + :arg index: The name of the index whose lifecycle step is to + change :arg body: The new lifecycle step to move to """ + if index in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "POST", _make_path("_ilm", "move", index), params=params, body=body ) @query_params() - def put_lifecycle(self, policy=None, body=None, params=None): + def put_lifecycle(self, policy, body=None, params=None): """ ``_ :arg policy: The name of the index lifecycle policy :arg body: The lifecycle policy definition to register """ + if policy in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'policy'.") + return self.transport.perform_request( "PUT", _make_path("_ilm", "policy", policy), params=params, body=body ) @query_params() - def remove_policy(self, index=None, params=None): + def remove_policy(self, index, params=None): """ ``_ :arg index: The name of the index to remove policy on """ + if index in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "POST", _make_path(index, "_ilm", "remove"), params=params ) @query_params() - def retry(self, index=None, params=None): + def retry(self, index, params=None): """ ``_ - :arg index: The name of the indices (comma-separated) whose failed - lifecycle step is to be retry + :arg index: The name of the indices (comma-separated) whose + failed lifecycle step is to be retry """ + if index in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "POST", _make_path(index, "_ilm", "retry"), params=params ) @@ -93,6 +117,7 @@ class IlmClient(NamespacedClient): def start(self, params=None): """ ``_ + """ return self.transport.perform_request("POST", "/_ilm/start", params=params) @@ -100,5 +125,6 @@ class IlmClient(NamespacedClient): def stop(self, params=None): """ ``_ + """ return self.transport.perform_request("POST", "/_ilm/stop", params=params) diff --git a/elasticsearch/client/indices.py b/elasticsearch/client/indices.py index cee065db..073f2b7f 100644 --- a/elasticsearch/client/indices.py +++ b/elasticsearch/client/indices.py @@ -2,19 +2,17 @@ from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH class IndicesClient(NamespacedClient): - @query_params("format", "prefer_local") - def analyze(self, index=None, body=None, params=None): + @query_params("index") + def analyze(self, body=None, index=None, params=None): """ - Perform the analysis process on a text and return the tokens breakdown of the text. - ``_ + Performs the analysis process on a text and return the tokens breakdown of the + text. + ``_ + :arg body: Define analyzer/tokenizer parameters and the text on + which the analysis should be performed + :arg index: The name of the index to scope the operation :arg index: The name of the index to scope the operation - :arg body: Define analyzer/tokenizer parameters and the text on which - the analysis should be performed - :arg format: Format of the output, default 'detailed', valid choices - are: 'detailed', 'text' - :arg prefer_local: With `true`, specify that a local shard should be - used if available, with `false`, use a random shard (default: true) """ return self.transport.perform_request( "GET", _make_path(index, "_analyze"), params=params, body=body @@ -23,20 +21,19 @@ class IndicesClient(NamespacedClient): @query_params("allow_no_indices", "expand_wildcards", "ignore_unavailable") def refresh(self, index=None, params=None): """ - Explicitly refresh one or more index, making all operations performed - since the last refresh available for search. - ``_ + Performs the refresh operation in one or more indices. + ``_ - :arg index: A comma-separated list of index names; use `_all` or empty - string to perform the operation on all indices + :arg index: A comma-separated list of index names; use `_all` or + empty string to perform the operation on all indices :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) """ return self.transport.perform_request( "POST", _make_path(index, "_refresh"), params=params @@ -51,52 +48,54 @@ class IndicesClient(NamespacedClient): ) def flush(self, index=None, params=None): """ - Explicitly flush one or more indices. - ``_ + Performs the flush operation on one or more indices. + ``_ - :arg index: A comma-separated list of index names; use `_all` or empty - string for all indices + :arg index: A comma-separated list of index names; use `_all` or + empty string for all indices :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open :arg force: Whether a flush should be forced even if it is not necessarily needed ie. if no changes will be committed to the index. - This is useful if transaction log IDs should be incremented even if - no uncommitted changes are present. (This setting can be considered - as internal) - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg wait_if_ongoing: If set to true the flush operation will block - until the flush can be executed if another flush operation is - already executing. The default is true. If set to false the flush - will be skipped iff if another flush operation is already running. + This is useful if transaction log IDs should be incremented even if no + uncommitted changes are present. (This setting can be considered as + internal) + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg wait_if_ongoing: If set to true the flush operation will + block until the flush can be executed if another flush operation is + already executing. The default is true. If set to false the flush will + be skipped iff if another flush operation is already running. """ return self.transport.perform_request( "POST", _make_path(index, "_flush"), params=params ) @query_params( - "master_timeout", "timeout", "wait_for_active_shards", "include_type_name", + "include_type_name", "master_timeout", "timeout", "wait_for_active_shards" ) def create(self, index, body=None, params=None): """ - Create an index in Elasticsearch. - ``_ + Creates an index with optional settings and mappings. + ``_ :arg index: The name of the index - :arg body: The configuration for the index (`settings` and `mappings`) + :arg body: The configuration for the index (`settings` and + `mappings`) + :arg include_type_name: Whether a type should be expected in the + body of the mappings. :arg master_timeout: Specify timeout for connection to master :arg timeout: Explicit operation timeout - :arg wait_for_active_shards: Set the number of active shards to wait for - before the operation returns. - :arg include_type_name: Specify whether requests and responses should include a - type name (default: depends on Elasticsearch version). + :arg wait_for_active_shards: Set the number of active shards to + wait for before the operation returns. """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "PUT", _make_path(index), params=params, body=body ) @@ -105,19 +104,20 @@ class IndicesClient(NamespacedClient): def clone(self, index, target, body=None, params=None): """ Clones an index - ``_ + ``_ :arg index: The name of the source index to clone :arg target: The name of the target index to clone into + :arg body: The configuration for the target index (`settings` + and `aliases`) :arg master_timeout: Specify timeout for connection to master :arg timeout: Explicit operation timeout - :arg wait_for_active_shards: Set the number of active shards to wait for - before the operation returns. + :arg wait_for_active_shards: Set the number of active shards to + wait for on the cloned index before the operation returns. """ - if index in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'index'.") - if target in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'target'.") + for param in (index, target): + if param in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument.") return self.transport.perform_request( "PUT", _make_path(index, "_clone", target), params=params, body=body @@ -129,36 +129,37 @@ class IndicesClient(NamespacedClient): "flat_settings", "ignore_unavailable", "include_defaults", - "local", "include_type_name", + "local", "master_timeout", ) - def get(self, index, feature=None, params=None): + def get(self, index, params=None): """ - The get index API allows to retrieve information about one or more indexes. - ``_ + Returns information about one or more indices. + ``_ :arg index: A comma-separated list of index names - :arg allow_no_indices: Ignore if a wildcard expression resolves to no - concrete indices (default: false) - :arg expand_wildcards: Whether wildcard expressions should get expanded - to open or closed indices (default: open), default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg flat_settings: Return settings in flat format (default: false) - :arg ignore_unavailable: Ignore unavailable indexes (default: false) - :arg include_defaults: Whether to return all default setting for each of - the indices., default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg include_type_name: Specify whether requests and responses should include a - type name (default: depends on Elasticsearch version). + :arg allow_no_indices: Ignore if a wildcard expression resolves + to no concrete indices (default: false) + :arg expand_wildcards: Whether wildcard expressions should get + expanded to open or closed indices (default: open) Valid choices: open, + closed, none, all Default: open + :arg flat_settings: Return settings in flat format (default: + false) + :arg ignore_unavailable: Ignore unavailable indexes (default: + false) + :arg include_defaults: Whether to return all default setting for + each of the indices. + :arg include_type_name: Whether to add the type name to the + response (default: false) + :arg local: Return local information, do not retrieve the state + from master node (default: false) :arg master_timeout: Specify timeout for connection to master """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") - return self.transport.perform_request( - "GET", _make_path(index, feature), params=params - ) + + return self.transport.perform_request("GET", _make_path(index), params=params) @query_params( "allow_no_indices", @@ -170,25 +171,26 @@ class IndicesClient(NamespacedClient): ) def open(self, index, params=None): """ - Open a closed index to make it available for search. - ``_ + Opens an index. + ``_ - :arg index: The name of the index + :arg index: A comma separated list of indices to open :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'closed', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: closed + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) :arg master_timeout: Specify timeout for connection to master :arg timeout: Explicit operation timeout - :arg wait_for_active_shards: Sets the number of active shards to wait - for before the operation returns. + :arg wait_for_active_shards: Sets the number of active shards to + wait for before the operation returns. """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "POST", _make_path(index, "_open"), params=params ) @@ -198,29 +200,31 @@ class IndicesClient(NamespacedClient): "expand_wildcards", "ignore_unavailable", "master_timeout", + "timeout", "wait_for_active_shards", ) def close(self, index, params=None): """ - Close an index to remove it's overhead from the cluster. Closed index - is blocked for read/write operations. - ``_ + Closes an index. + ``_ - :arg index: The name of the index + :arg index: A comma separated list of indices to close :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) :arg master_timeout: Specify timeout for connection to master - :arg wait_for_active_shards: Sets the number of active shards to wait - for before the operation returns. + :arg timeout: Explicit operation timeout + :arg wait_for_active_shards: Sets the number of active shards to + wait for before the operation returns. """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "POST", _make_path(index, "_close"), params=params ) @@ -229,27 +233,29 @@ class IndicesClient(NamespacedClient): "allow_no_indices", "expand_wildcards", "ignore_unavailable", - "timeout", "master_timeout", + "timeout", ) def delete(self, index, params=None): """ - Delete an index in Elasticsearch - ``_ + Deletes an index. + ``_ - :arg index: A comma-separated list of indices to delete; use `_all` or - `*` string to delete all indices - :arg allow_no_indices: Ignore if a wildcard expression resolves to no - concrete indices (default: false) - :arg expand_wildcards: Whether wildcard expressions should get expanded - to open or closed indices (default: open), default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Ignore unavailable indexes (default: false) + :arg index: A comma-separated list of indices to delete; use + `_all` or `*` string to delete all indices + :arg allow_no_indices: Ignore if a wildcard expression resolves + to no concrete indices (default: false) + :arg expand_wildcards: Whether wildcard expressions should get + expanded to open or closed indices (default: open) Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Ignore unavailable indexes (default: + false) :arg master_timeout: Specify timeout for connection to master :arg timeout: Explicit operation timeout """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "DELETE", _make_path(index), params=params ) @@ -264,49 +270,54 @@ class IndicesClient(NamespacedClient): ) def exists(self, index, params=None): """ - Return a boolean indicating whether given index exists. - ``_ + Returns information about whether a particular index exists. + ``_ :arg index: A comma-separated list of index names - :arg allow_no_indices: Ignore if a wildcard expression resolves to no - concrete indices (default: false) - :arg expand_wildcards: Whether wildcard expressions should get expanded - to open or closed indices (default: open), default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg flat_settings: Return settings in flat format (default: false) - :arg ignore_unavailable: Ignore unavailable indexes (default: false) - :arg include_defaults: Whether to return all default setting for each of - the indices., default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) + :arg allow_no_indices: Ignore if a wildcard expression resolves + to no concrete indices (default: false) + :arg expand_wildcards: Whether wildcard expressions should get + expanded to open or closed indices (default: open) Valid choices: open, + closed, none, all Default: open + :arg flat_settings: Return settings in flat format (default: + false) + :arg ignore_unavailable: Ignore unavailable indexes (default: + false) + :arg include_defaults: Whether to return all default setting for + each of the indices. + :arg local: Return local information, do not retrieve the state + from master node (default: false) """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request("HEAD", _make_path(index), params=params) @query_params("allow_no_indices", "expand_wildcards", "ignore_unavailable", "local") def exists_type(self, index, doc_type, params=None): """ - Check if a type/types exists in an index/indices. - ``_ + Returns information about whether a particular document type exists. + (DEPRECATED) + ``_ - :arg index: A comma-separated list of index names; use `_all` to check - the types across all indices + :arg index: A comma-separated list of index names; use `_all` to + check the types across all indices :arg doc_type: A comma-separated list of document types to check :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg local: Return local information, do not retrieve the state from - master node (default: false) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg local: Return local information, do not retrieve the state + from master node (default: false) """ for param in (index, doc_type): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "HEAD", _make_path(index, "_mapping", doc_type), params=params ) @@ -315,67 +326,67 @@ class IndicesClient(NamespacedClient): "allow_no_indices", "expand_wildcards", "ignore_unavailable", + "include_type_name", "master_timeout", "timeout", - "include_type_name", ) - def put_mapping(self, body, doc_type=None, index=None, params=None): + def put_mapping(self, body, index=None, doc_type=None, params=None): """ - Register specific mapping definition for a specific type. - ``_ + Updates the index mappings. + ``_ :arg body: The mapping definition + :arg index: A comma-separated list of index names the mapping + should be added to (supports wildcards); use `_all` or omit to add the + mapping on all indices. :arg doc_type: The name of the document type - :arg index: A comma-separated list of index names the mapping should be - added to (supports wildcards); use `_all` or omit to add the mapping - on all indices. :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg include_type_name: Whether a type should be expected in the + body of the mappings. :arg master_timeout: Specify timeout for connection to master :arg timeout: Explicit operation timeout - :arg include_type_name: Specify whether requests and responses should include a - type name (default: depends on Elasticsearch version). """ - for param in (body,): - if param in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument.") + if body in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( - "PUT", _make_path(index, "_mapping", doc_type), params=params, body=body + "PUT", _make_path(index, doc_type, "_mapping"), params=params, body=body ) @query_params( "allow_no_indices", "expand_wildcards", "ignore_unavailable", - "local", "include_type_name", + "local", "master_timeout", ) def get_mapping(self, index=None, doc_type=None, params=None): """ - Retrieve mapping definition of index or index/type. - ``_ + Returns mappings for one or more indices. + ``_ :arg index: A comma-separated list of index names :arg doc_type: A comma-separated list of document types :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg include_type_name: Specify whether requests and responses should include a - type name (default: depends on Elasticsearch version). + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg include_type_name: Whether to add the type name to the + response (default: false) + :arg local: Return local information, do not retrieve the state + from master node (default: false) :arg master_timeout: Specify timeout for connection to master """ return self.transport.perform_request( @@ -387,13 +398,13 @@ class IndicesClient(NamespacedClient): "expand_wildcards", "ignore_unavailable", "include_defaults", - "local", "include_type_name", + "local", ) def get_field_mapping(self, fields, index=None, doc_type=None, params=None): """ - Retrieve mapping definition of a specific field. - ``_ + Returns mapping for one or more fields. + ``_ :arg fields: A comma-separated list of fields :arg index: A comma-separated list of index names @@ -401,65 +412,73 @@ class IndicesClient(NamespacedClient): :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg include_defaults: Whether the default mapping values should be - returned as well - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg include_type_name: Specify whether requests and responses should include a - type name (default: depends on Elasticsearch version). + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg include_defaults: Whether the default mapping values should + be returned as well + :arg include_type_name: Whether a type should be returned in the + body of the mappings. + :arg local: Return local information, do not retrieve the state + from master node (default: false) """ if fields in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'fields'.") + return self.transport.perform_request( "GET", _make_path(index, "_mapping", doc_type, "field", fields), params=params, ) - @query_params("master_timeout") + @query_params("master_timeout", "timeout") def put_alias(self, index, name, body=None, params=None): """ - Create an alias for a specific index/indices. - ``_ + Creates or updates an alias. + ``_ - :arg index: A comma-separated list of index names the alias should point - to (supports wildcards); use `_all` to perform the operation on all - indices. + :arg index: A comma-separated list of index names the alias + should point to (supports wildcards); use `_all` to perform the + operation on all indices. :arg name: The name of the alias to be created or updated - :arg body: The settings for the alias, such as `routing` or `filter` + :arg body: The settings for the alias, such as `routing` or + `filter` :arg master_timeout: Specify timeout for connection to master + :arg timeout: Explicit timestamp for the document """ for param in (index, name): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path(index, "_alias", name), params=params, body=body ) @query_params("allow_no_indices", "expand_wildcards", "ignore_unavailable", "local") - def exists_alias(self, index=None, name=None, params=None): + def exists_alias(self, name, index=None, params=None): """ - Return a boolean indicating whether given alias exists. - ``_ + Returns information about whether a particular alias exists. + ``_ - :arg index: A comma-separated list of index names to filter aliases :arg name: A comma-separated list of alias names to return + :arg index: A comma-separated list of index names to filter + aliases :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'all', valid choices - are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg local: Return local information, do not retrieve the state from - master node (default: false) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: all + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg local: Return local information, do not retrieve the state + from master node (default: false) """ + if name in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'name'.") + return self.transport.perform_request( "HEAD", _make_path(index, "_alias", name), params=params ) @@ -467,21 +486,22 @@ class IndicesClient(NamespacedClient): @query_params("allow_no_indices", "expand_wildcards", "ignore_unavailable", "local") def get_alias(self, index=None, name=None, params=None): """ - Retrieve a specified alias. - ``_ + Returns an alias. + ``_ - :arg index: A comma-separated list of index names to filter aliases + :arg index: A comma-separated list of index names to filter + aliases :arg name: A comma-separated list of alias names to return :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'all', valid choices - are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg local: Return local information, do not retrieve the state from - master node (default: false) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: all + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg local: Return local information, do not retrieve the state + from master node (default: false) """ return self.transport.perform_request( "GET", _make_path(index, "_alias", name), params=params @@ -490,8 +510,8 @@ class IndicesClient(NamespacedClient): @query_params("master_timeout", "timeout") def update_aliases(self, body, params=None): """ - Update specified aliases. - ``_ + Updates index aliases. + ``_ :arg body: The definition of `actions` to perform :arg master_timeout: Specify timeout for connection to master @@ -499,6 +519,7 @@ class IndicesClient(NamespacedClient): """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "POST", "/_aliases", params=params, body=body ) @@ -506,20 +527,20 @@ class IndicesClient(NamespacedClient): @query_params("master_timeout", "timeout") def delete_alias(self, index, name, params=None): """ - Delete specific alias. - ``_ + Deletes an alias. + ``_ - :arg index: A comma-separated list of index names (supports wildcards); - use `_all` for all indices + :arg index: A comma-separated list of index names (supports + wildcards); use `_all` for all indices :arg name: A comma-separated list of aliases to delete (supports - wildcards); use `_all` to delete all aliases for the specified - indices. + wildcards); use `_all` to delete all aliases for the specified indices. :arg master_timeout: Specify timeout for connection to master - :arg timeout: Explicit timeout for the operation + :arg timeout: Explicit timestamp for the document """ for param in (index, name): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "DELETE", _make_path(index, "_alias", name), params=params ) @@ -527,32 +548,34 @@ class IndicesClient(NamespacedClient): @query_params( "create", "flat_settings", + "include_type_name", "master_timeout", "order", "timeout", - "include_type_name", ) def put_template(self, name, body, params=None): """ - Create an index template that will automatically be applied to new - indices created. - ``_ + Creates or updates an index template. + ``_ :arg name: The name of the template :arg body: The template definition - :arg create: Whether the index template should only be added if new or - can also replace an existing one, default False - :arg flat_settings: Return settings in flat format (default: false) + :arg create: Whether the index template should only be added if + new or can also replace an existing one + :arg flat_settings: Return settings in flat format (default: + false) + :arg include_type_name: Whether a type should be returned in the + body of the mappings. :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) + :arg order: The order for this template when merging multiple + matching ones (higher numbers are merged later, overriding the lower + numbers) :arg timeout: Explicit operation timeout - :arg include_type_name: Specify whether requests and responses should include a - type name (default: depends on Elasticsearch version). """ for param in (name, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_template", name), params=params, body=body ) @@ -560,36 +583,39 @@ class IndicesClient(NamespacedClient): @query_params("flat_settings", "local", "master_timeout") def exists_template(self, name, params=None): """ - Return a boolean indicating whether given template exists. - ``_ + Returns information about whether a particular index template exists. + ``_ :arg name: The comma separated names of the index templates - :arg flat_settings: Return settings in flat format (default: false) - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg flat_settings: Return settings in flat format (default: + false) + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node """ if name in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'name'.") + return self.transport.perform_request( "HEAD", _make_path("_template", name), params=params ) - @query_params("flat_settings", "local", "master_timeout", "include_type_name") + @query_params("flat_settings", "include_type_name", "local", "master_timeout") def get_template(self, name=None, params=None): """ - Retrieve an index template by its name. - ``_ + Returns an index template. + ``_ - :arg name: The name of the template - :arg flat_settings: Return settings in flat format (default: false) - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg include_type_name: Specify whether requests and responses should include a - type name (default: depends on Elasticsearch version). + :arg name: The comma separated names of the index templates + :arg flat_settings: Return settings in flat format (default: + false) + :arg include_type_name: Whether a type should be returned in the + body of the mappings. + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node """ return self.transport.perform_request( "GET", _make_path("_template", name), params=params @@ -598,8 +624,8 @@ class IndicesClient(NamespacedClient): @query_params("master_timeout", "timeout") def delete_template(self, name, params=None): """ - Delete an index template by its name. - ``_ + Deletes an index template. + ``_ :arg name: The name of the template :arg master_timeout: Specify timeout for connection to master @@ -607,6 +633,7 @@ class IndicesClient(NamespacedClient): """ if name in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'name'.") + return self.transport.perform_request( "DELETE", _make_path("_template", name), params=params ) @@ -622,25 +649,26 @@ class IndicesClient(NamespacedClient): ) def get_settings(self, index=None, name=None, params=None): """ - Retrieve settings for one or more (or all) indices. - ``_ + Returns settings for one or more indices. + ``_ - :arg index: A comma-separated list of index names; use `_all` or empty - string to perform the operation on all indices + :arg index: A comma-separated list of index names; use `_all` or + empty string to perform the operation on all indices :arg name: The name of the settings that should be included :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default ['open', 'closed'], - valid choices are: 'open', 'closed', 'none', 'all' - :arg flat_settings: Return settings in flat format (default: false) - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg include_defaults: Whether to return all default setting for each of - the indices., default False - :arg local: Return local information, do not retrieve the state from - master node (default: false) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: ['open', 'closed'] + :arg flat_settings: Return settings in flat format (default: + false) + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg include_defaults: Whether to return all default setting for + each of the indices. + :arg local: Return local information, do not retrieve the state + from master node (default: false) :arg master_timeout: Specify timeout for connection to master """ return self.transport.perform_request( @@ -653,34 +681,36 @@ class IndicesClient(NamespacedClient): "flat_settings", "ignore_unavailable", "master_timeout", - "timeout", "preserve_existing", + "timeout", ) def put_settings(self, body, index=None, params=None): """ - Change specific index level settings in real time. - ``_ + Updates the index settings. + ``_ :arg body: The index settings to be updated - :arg index: A comma-separated list of index names; use `_all` or empty - string to perform the operation on all indices + :arg index: A comma-separated list of index names; use `_all` or + empty string to perform the operation on all indices :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg flat_settings: Return settings in flat format (default: false) - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg flat_settings: Return settings in flat format (default: + false) + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) :arg master_timeout: Specify timeout for connection to master - :arg preserve_existing: Whether to update existing settings. If set to - `true` existing settings on an index remain unchanged, the default - is `false` + :arg preserve_existing: Whether to update existing settings. If + set to `true` existing settings on an index remain unchanged, the + default is `false` :arg timeout: Explicit operation timeout """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "PUT", _make_path(index, "_settings"), params=params, body=body ) @@ -699,65 +729,63 @@ class IndicesClient(NamespacedClient): ) def stats(self, index=None, metric=None, params=None): """ - Retrieve statistics on different operations happening on an index. - ``_ + Provides statistics on operations happening in an index. + ``_ - :arg index: A comma-separated list of index names; use `_all` or empty - string to perform the operation on all indices - :arg metric: Limit the information returned the specific metrics. - :arg completion_fields: A comma-separated list of fields for `fielddata` - and `suggest` index metric (supports wildcards) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg fielddata_fields: A comma-separated list of fields for `fielddata` - index metric (supports wildcards) - :arg fields: A comma-separated list of fields for `fielddata` and - `completion` index metric (supports wildcards) - :arg forbid_closed_indices: If set to false stats will also collected - from closed indices if explicitly specified or if expand_wildcards - expands to closed indices, default True - :arg groups: A comma-separated list of search groups for `search` index - metric - :arg include_segment_file_sizes: Whether to report the aggregated disk - usage of each one of the Lucene index files (only applies if segment - stats are requested), default False - :arg include_unloaded_segments: If set to true segment stats will - include stats for segments that are not currently loaded into - memory, default False - :arg level: Return stats aggregated at cluster, index or shard level, - default 'indices', valid choices are: 'cluster', 'indices', 'shards' - :arg types: A comma-separated list of document types for the `indexing` - index metric + :arg index: A comma-separated list of index names; use `_all` or + empty string to perform the operation on all indices + :arg metric: Limit the information returned the specific + metrics. Valid choices: _all, completion, docs, fielddata, query_cache, + flush, get, indexing, merge, request_cache, refresh, search, segments, + store, warmer, suggest + :arg completion_fields: A comma-separated list of fields for + `fielddata` and `suggest` index metric (supports wildcards) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg fielddata_fields: A comma-separated list of fields for + `fielddata` index metric (supports wildcards) + :arg fields: A comma-separated list of fields for `fielddata` + and `completion` index metric (supports wildcards) + :arg forbid_closed_indices: If set to false stats will also + collected from closed indices if explicitly specified or if + expand_wildcards expands to closed indices Default: True + :arg groups: A comma-separated list of search groups for + `search` index metric + :arg include_segment_file_sizes: Whether to report the + aggregated disk usage of each one of the Lucene index files (only + applies if segment stats are requested) + :arg include_unloaded_segments: If set to true segment stats + will include stats for segments that are not currently loaded into + memory + :arg level: Return stats aggregated at cluster, index or shard + level Valid choices: cluster, indices, shards Default: indices + :arg types: A comma-separated list of document types for the + `indexing` index metric """ return self.transport.perform_request( "GET", _make_path(index, "_stats", metric), params=params ) @query_params( - "allow_no_indices", - "expand_wildcards", - "ignore_unavailable", - "operation_threading", - "verbose", + "allow_no_indices", "expand_wildcards", "ignore_unavailable", "verbose" ) def segments(self, index=None, params=None): """ - Provide low level segments information that a Lucene index (shard level) is built with. - ``_ + Provides low-level information about segments in a Lucene index. + ``_ - :arg index: A comma-separated list of index names; use `_all` or empty - string to perform the operation on all indices + :arg index: A comma-separated list of index names; use `_all` or + empty string to perform the operation on all indices :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg operation_threading: TODO: ? - :arg verbose: Includes detailed memory usage by Lucene., default False + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg verbose: Includes detailed memory usage by Lucene. """ return self.transport.perform_request( "GET", _make_path(index, "_segments"), params=params @@ -774,45 +802,44 @@ class IndicesClient(NamespacedClient): "explain", "ignore_unavailable", "lenient", - "operation_threading", "q", "rewrite", ) - def validate_query(self, index=None, doc_type=None, body=None, params=None): + def validate_query(self, body=None, index=None, doc_type=None, params=None): """ - Validate a potentially expensive query without executing it. - ``_ + Allows a user to validate a potentially expensive query without executing it. + ``_ - :arg index: A comma-separated list of index names to restrict the - operation; use `_all` or empty string to perform the operation on - all indices - :arg doc_type: A comma-separated list of document types to restrict the - operation; leave empty to perform the operation on all types :arg body: The query definition specified with the Query DSL - :arg all_shards: Execute validation on all shards instead of one random - shard per index + :arg index: A comma-separated list of index names to restrict + the operation; use `_all` or empty string to perform the operation on + all indices + :arg doc_type: A comma-separated list of document types to + restrict the operation; leave empty to perform the operation on all + types + :arg all_shards: Execute validation on all shards instead of one + random shard per index :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg analyze_wildcard: Specify whether wildcard and prefix queries - should be analyzed (default: false) + :arg analyze_wildcard: Specify whether wildcard and prefix + queries should be analyzed (default: false) :arg analyzer: The analyzer to use for the query string - :arg default_operator: The default operator for query string query (AND - or OR), default 'OR', valid choices are: 'AND', 'OR' - :arg df: The field to use as default where no field prefix is given in - the query string - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' + :arg default_operator: The default operator for query string + query (AND or OR) Valid choices: AND, OR Default: OR + :arg df: The field to use as default where no field prefix is + given in the query string + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open :arg explain: Return detailed information about the error - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg lenient: Specify whether format-based query failures (such as - providing text to a numeric field) should be ignored - :arg operation_threading: TODO: ? + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg lenient: Specify whether format-based query failures (such + as providing text to a numeric field) should be ignored :arg q: Query in the Lucene query string syntax - :arg rewrite: Provide a more detailed explanation showing the actual - Lucene query that will be executed. + :arg rewrite: Provide a more detailed explanation showing the + actual Lucene query that will be executed. """ return self.transport.perform_request( "GET", @@ -824,36 +851,35 @@ class IndicesClient(NamespacedClient): @query_params( "allow_no_indices", "expand_wildcards", - "field_data", "fielddata", "fields", "ignore_unavailable", + "index", "query", - "recycler", "request", ) def clear_cache(self, index=None, params=None): """ - Clear either all caches or specific cached associated with one ore more indices. - ``_ + Clears all or specific caches for one or more indices. + ``_ - :arg index: A comma-separated list of index name to limit the operation + :arg index: A comma-separated list of index name to limit the + operation :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg field_data: Clear field data + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open :arg fielddata: Clear field data - :arg fields: A comma-separated list of fields to clear when using the - `field_data` parameter (default: all) - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) + :arg fields: A comma-separated list of fields to clear when + using the `fielddata` parameter (default: all) + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg index: A comma-separated list of index name to limit the + operation :arg query: Clear query caches - :arg recycler: Clear the recycler cache :arg request: Clear request cache - :arg request_cache: Clear request cache """ return self.transport.perform_request( "POST", _make_path(index, "_cache", "clear"), params=params @@ -862,17 +888,15 @@ class IndicesClient(NamespacedClient): @query_params("active_only", "detailed") def recovery(self, index=None, params=None): """ - The indices recovery API provides insight into on-going shard - recoveries. Recovery status may be reported for specific indices, or - cluster-wide. - ``_ + Returns information about ongoing index shard recoveries. + ``_ - :arg index: A comma-separated list of index names; use `_all` or empty - string to perform the operation on all indices - :arg active_only: Display only those recoveries that are currently on- - going, default False - :arg detailed: Whether to display detailed information about shard - recovery, default False + :arg index: A comma-separated list of index names; use `_all` or + empty string to perform the operation on all indices + :arg active_only: Display only those recoveries that are + currently on-going + :arg detailed: Whether to display detailed information about + shard recovery """ return self.transport.perform_request( "GET", _make_path(index, "_recovery"), params=params @@ -887,23 +911,23 @@ class IndicesClient(NamespacedClient): ) def upgrade(self, index=None, params=None): """ - Upgrade one or more indices to the latest format through an API. - ``_ + The _upgrade API is no longer useful and will be removed. + ``_ - :arg index: A comma-separated list of index names; use `_all` or empty - string to perform the operation on all indices + :arg index: A comma-separated list of index names; use `_all` or + empty string to perform the operation on all indices :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg only_ancient_segments: If true, only ancient (an older Lucene major - release) segments will be upgraded - :arg wait_for_completion: Specify whether the request should block until - the all segments are upgraded (default: false) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg only_ancient_segments: If true, only ancient (an older + Lucene major release) segments will be upgraded + :arg wait_for_completion: Specify whether the request should + block until the all segments are upgraded (default: false) """ return self.transport.perform_request( "POST", _make_path(index, "_upgrade"), params=params @@ -912,19 +936,19 @@ class IndicesClient(NamespacedClient): @query_params("allow_no_indices", "expand_wildcards", "ignore_unavailable") def get_upgrade(self, index=None, params=None): """ - Monitor how much of one or more index is upgraded. - ``_ + The _upgrade API is no longer useful and will be removed. + ``_ - :arg index: A comma-separated list of index names; use `_all` or empty - string to perform the operation on all indices + :arg index: A comma-separated list of index names; use `_all` or + empty string to perform the operation on all indices :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) """ return self.transport.perform_request( "GET", _make_path(index, "_upgrade"), params=params @@ -933,53 +957,45 @@ class IndicesClient(NamespacedClient): @query_params("allow_no_indices", "expand_wildcards", "ignore_unavailable") def flush_synced(self, index=None, params=None): """ - Perform a normal flush, then add a generated unique marker (sync_id) to all shards. - ``_ + Performs a synced flush operation on one or more indices. + ``_ - :arg index: A comma-separated list of index names; use `_all` or empty - string for all indices + :arg index: A comma-separated list of index names; use `_all` or + empty string for all indices :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) """ return self.transport.perform_request( "POST", _make_path(index, "_flush", "synced"), params=params ) @query_params( - "allow_no_indices", - "expand_wildcards", - "ignore_unavailable", - "operation_threading", - "status", + "allow_no_indices", "expand_wildcards", "ignore_unavailable", "status" ) def shard_stores(self, index=None, params=None): """ - Provides store information for shard copies of indices. Store - information reports on which nodes shard copies exist, the shard copy - version, indicating how recent they are, and any exceptions encountered - while opening the shard index or from earlier engine failure. - ``_ + Provides store information for shard copies of indices. + ``_ - :arg index: A comma-separated list of index names; use `_all` or empty - string to perform the operation on all indices + :arg index: A comma-separated list of index names; use `_all` or + empty string to perform the operation on all indices :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg operation_threading: TODO: ? - :arg status: A comma-separated list of statuses used to filter on shards - to get store information for, valid choices are: 'green', 'yellow', - 'red', 'all' + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg status: A comma-separated list of statuses used to filter + on shards to get store information for Valid choices: green, yellow, + red, all """ return self.transport.perform_request( "GET", _make_path(index, "_shard_stores"), params=params @@ -992,131 +1008,123 @@ class IndicesClient(NamespacedClient): "ignore_unavailable", "max_num_segments", "only_expunge_deletes", - "operation_threading", - "wait_for_merge", ) def forcemerge(self, index=None, params=None): """ - The force merge API allows to force merging of one or more indices - through an API. The merge relates to the number of segments a Lucene - index holds within each shard. The force merge operation allows to - reduce the number of segments by merging them. + Performs the force merge operation on one or more indices. + ``_ - This call will block until the merge is complete. If the http - connection is lost, the request will continue in the background, and - any new requests will block until the previous force merge is complete. - ``_ - - :arg index: A comma-separated list of index names; use `_all` or empty - string to perform the operation on all indices + :arg index: A comma-separated list of index names; use `_all` or + empty string to perform the operation on all indices :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'open', valid - choices are: 'open', 'closed', 'none', 'all' - :arg flush: Specify whether the index should be flushed after performing - the operation (default: true) - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) - :arg max_num_segments: The number of segments the index should be merged - into (default: dynamic) - :arg only_expunge_deletes: Specify whether the operation should only - expunge deleted documents (for pre 7.x ES clusters) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg flush: Specify whether the index should be flushed after + performing the operation (default: true) + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + :arg max_num_segments: The number of segments the index should + be merged into (default: dynamic) + :arg only_expunge_deletes: Specify whether the operation should + only expunge deleted documents """ return self.transport.perform_request( "POST", _make_path(index, "_forcemerge"), params=params ) - @query_params("master_timeout", "timeout", "wait_for_active_shards") + @query_params( + "copy_settings", "master_timeout", "timeout", "wait_for_active_shards" + ) def shrink(self, index, target, body=None, params=None): """ - The shrink index API allows you to shrink an existing index into a new - index with fewer primary shards. The number of primary shards in the - target index must be a factor of the shards in the source index. For - example an index with 8 primary shards can be shrunk into 4, 2 or 1 - primary shards or an index with 15 primary shards can be shrunk into 5, - 3 or 1. If the number of shards in the index is a prime number it can - only be shrunk into a single primary shard. Before shrinking, a - (primary or replica) copy of every shard in the index must be present - on the same node. - ``_ + Allow to shrink an existing index into a new index with fewer primary shards. + ``_ :arg index: The name of the source index to shrink :arg target: The name of the target index to shrink into - :arg body: The configuration for the target index (`settings` and - `aliases`) + :arg body: The configuration for the target index (`settings` + and `aliases`) + :arg copy_settings: whether or not to copy settings from the + source index (defaults to false) :arg master_timeout: Specify timeout for connection to master :arg timeout: Explicit operation timeout - :arg wait_for_active_shards: Set the number of active shards to wait for - on the shrunken index before the operation returns. + :arg wait_for_active_shards: Set the number of active shards to + wait for on the shrunken index before the operation returns. """ for param in (index, target): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path(index, "_shrink", target), params=params, body=body ) - @query_params("master_timeout", "timeout", "wait_for_active_shards") + @query_params( + "copy_settings", "master_timeout", "timeout", "wait_for_active_shards" + ) def split(self, index, target, body=None, params=None): """ - ``_ + Allows you to split an existing index into a new index with more primary + shards. + ``_ :arg index: The name of the source index to split :arg target: The name of the target index to split into - :arg body: The configuration for the target index (`settings` and - `aliases`) + :arg body: The configuration for the target index (`settings` + and `aliases`) + :arg copy_settings: whether or not to copy settings from the + source index (defaults to false) :arg master_timeout: Specify timeout for connection to master :arg timeout: Explicit operation timeout - :arg wait_for_active_shards: Set the number of active shards to wait for - on the shrunken index before the operation returns. + :arg wait_for_active_shards: Set the number of active shards to + wait for on the shrunken index before the operation returns. """ for param in (index, target): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path(index, "_split", target), params=params, body=body ) @query_params( "dry_run", + "include_type_name", "master_timeout", "timeout", "wait_for_active_shards", - "include_type_name", ) - def rollover(self, alias, new_index=None, body=None, params=None): + def rollover(self, alias, body=None, new_index=None, params=None): """ - The rollover index API rolls an alias over to a new index when the - existing index is considered to be too large or too old. - - The API accepts a single alias name and a list of conditions. The alias - must point to a single index only. If the index satisfies the specified - conditions then a new index is created and the alias is switched to - point to the new alias. - ``_ + Updates an alias to point to a new index when the existing index is considered + to be too large or too old. + ``_ :arg alias: The name of the alias to rollover + :arg body: The conditions that needs to be met for executing + rollover :arg new_index: The name of the rollover index - :arg body: The conditions that needs to be met for executing rollover - :arg dry_run: If set to true the rollover action will only be validated - but not actually performed even if a condition matches. The default - is false + :arg dry_run: If set to true the rollover action will only be + validated but not actually performed even if a condition matches. The + default is false + :arg include_type_name: Whether a type should be included in the + body of the mappings. :arg master_timeout: Specify timeout for connection to master :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 returns. - :arg include_type_name: Specify whether requests and responses should include a - type name (default: depends on Elasticsearch version). + :arg wait_for_active_shards: Set the number of active shards to + wait for on the newly created rollover index before the operation + returns. """ if alias in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'alias'.") + return self.transport.perform_request( "POST", _make_path(alias, "_rollover", new_index), params=params, body=body ) - # X-pack APIS @query_params( "allow_no_indices", "expand_wildcards", @@ -1133,18 +1141,19 @@ class IndicesClient(NamespacedClient): :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'closed', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: closed + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) :arg master_timeout: Specify timeout for connection to master :arg timeout: Explicit operation timeout - :arg wait_for_active_shards: Sets the number of active shards to wait - for before the operation returns. + :arg wait_for_active_shards: Sets the number of active shards to + wait for before the operation returns. """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "POST", _make_path(index, "_freeze"), params=params ) @@ -1165,18 +1174,42 @@ class IndicesClient(NamespacedClient): :arg allow_no_indices: Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) - :arg expand_wildcards: Whether to expand wildcard expression to concrete - indices that are open, closed or both., default 'closed', valid - choices are: 'open', 'closed', 'none', 'all' - :arg ignore_unavailable: Whether specified concrete indices should be - ignored when unavailable (missing or closed) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: closed + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) :arg master_timeout: Specify timeout for connection to master :arg timeout: Explicit operation timeout - :arg wait_for_active_shards: Sets the number of active shards to wait - for before the operation returns. + :arg wait_for_active_shards: Sets the number of active shards to + wait for before the operation returns. """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "POST", _make_path(index, "_unfreeze"), params=params ) + + @query_params("allow_no_indices", "expand_wildcards", "ignore_unavailable") + def reload_search_analyzers(self, index, params=None): + """ + ``_ + + :arg index: A comma-separated list of index names to reload + analyzers for + :arg allow_no_indices: Whether to ignore if a wildcard indices + expression resolves into no concrete indices. (This includes `_all` + string or when no indices have been specified) + :arg expand_wildcards: Whether to expand wildcard expression to + concrete indices that are open, closed or both. Valid choices: open, + closed, none, all Default: open + :arg ignore_unavailable: Whether specified concrete indices + should be ignored when unavailable (missing or closed) + """ + if index in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'index'.") + + return self.transport.perform_request( + "GET", _make_path(index, "_reload_search_analyzers"), params=params + ) diff --git a/elasticsearch/client/ingest.py b/elasticsearch/client/ingest.py index bc66c331..0ef5af6d 100644 --- a/elasticsearch/client/ingest.py +++ b/elasticsearch/client/ingest.py @@ -5,11 +5,13 @@ class IngestClient(NamespacedClient): @query_params("master_timeout") def get_pipeline(self, id=None, params=None): """ - ``_ + Returns a pipeline. + ``_ - :arg id: Comma separated list of pipeline ids. Wildcards supported - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg id: Comma separated list of pipeline ids. Wildcards + supported + :arg master_timeout: Explicit operation timeout for connection + to master node """ return self.transport.perform_request( "GET", _make_path("_ingest", "pipeline", id), params=params @@ -18,17 +20,19 @@ class IngestClient(NamespacedClient): @query_params("master_timeout", "timeout") def put_pipeline(self, id, body, params=None): """ - ``_ + Creates or updates a pipeline. + ``_ :arg id: Pipeline ID :arg body: The ingest definition - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg master_timeout: Explicit operation timeout for connection + to master node :arg timeout: Explicit operation timeout """ for param in (id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_ingest", "pipeline", id), params=params, body=body ) @@ -36,15 +40,17 @@ class IngestClient(NamespacedClient): @query_params("master_timeout", "timeout") def delete_pipeline(self, id, params=None): """ - ``_ + Deletes a pipeline. + ``_ :arg id: Pipeline ID - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg master_timeout: Explicit operation timeout for connection + to master node :arg timeout: Explicit operation timeout """ if id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'id'.") + return self.transport.perform_request( "DELETE", _make_path("_ingest", "pipeline", id), params=params ) @@ -52,15 +58,17 @@ class IngestClient(NamespacedClient): @query_params("verbose") def simulate(self, body, id=None, params=None): """ - ``_ + Allows to simulate a pipeline with example documents. + ``_ :arg body: The simulate definition :arg id: Pipeline ID - :arg verbose: Verbose mode. Display data output for each processor in - executed pipeline, default False + :arg verbose: Verbose mode. Display data output for each + processor in executed pipeline """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "GET", _make_path("_ingest", "pipeline", id, "_simulate"), @@ -71,7 +79,9 @@ class IngestClient(NamespacedClient): @query_params() def processor_grok(self, params=None): """ + Returns a list of the built-in patterns. ``_ + """ return self.transport.perform_request( "GET", "/_ingest/processor/grok", params=params diff --git a/elasticsearch/client/license.py b/elasticsearch/client/license.py index 2f0fbc8c..f5e9609f 100644 --- a/elasticsearch/client/license.py +++ b/elasticsearch/client/license.py @@ -5,24 +5,26 @@ class LicenseClient(NamespacedClient): @query_params() def delete(self, params=None): """ - ``_ + ``_ + """ return self.transport.perform_request("DELETE", "/_license", params=params) @query_params("local") def get(self, params=None): """ - ``_ + ``_ - :arg local: Return local information, do not retrieve the state from - master node (default: false) + :arg local: Return local information, do not retrieve the state + from master node (default: false) """ return self.transport.perform_request("GET", "/_license", params=params) @query_params() def get_basic_status(self, params=None): """ - ``_ + ``_ + """ return self.transport.perform_request( "GET", "/_license/basic_status", params=params @@ -31,7 +33,8 @@ class LicenseClient(NamespacedClient): @query_params() def get_trial_status(self, params=None): """ - ``_ + ``_ + """ return self.transport.perform_request( "GET", "/_license/trial_status", params=params @@ -40,11 +43,11 @@ class LicenseClient(NamespacedClient): @query_params("acknowledge") def post(self, body=None, params=None): """ - ``_ + ``_ :arg body: licenses to be installed - :arg acknowledge: whether the user has acknowledged acknowledge messages - (default: false) + :arg acknowledge: whether the user has acknowledged acknowledge + messages (default: false) """ return self.transport.perform_request( "PUT", "/_license", params=params, body=body @@ -53,10 +56,10 @@ class LicenseClient(NamespacedClient): @query_params("acknowledge") def post_start_basic(self, params=None): """ - ``_ + ``_ - :arg acknowledge: whether the user has acknowledged acknowledge messages - (default: false) + :arg acknowledge: whether the user has acknowledged acknowledge + messages (default: false) """ return self.transport.perform_request( "POST", "/_license/start_basic", params=params @@ -65,12 +68,17 @@ class LicenseClient(NamespacedClient): @query_params("acknowledge", "doc_type") def post_start_trial(self, params=None): """ - ``_ + ``_ - :arg acknowledge: whether the user has acknowledged acknowledge messages - (default: false) - :arg doc_type: The type of trial license to generate (default: "trial") + :arg acknowledge: whether the user has acknowledged acknowledge + messages (default: false) + :arg doc_type: The type of trial license to generate (default: + "trial") """ + # type is a reserved word so it cannot be used, use doc_type instead + if "doc_type" in params: + params["type"] = params.pop("doc_type") + return self.transport.perform_request( "POST", "/_license/start_trial", params=params ) diff --git a/elasticsearch/client/migration.py b/elasticsearch/client/migration.py index dd32e531..6c193521 100644 --- a/elasticsearch/client/migration.py +++ b/elasticsearch/client/migration.py @@ -5,7 +5,7 @@ class MigrationClient(NamespacedClient): @query_params() def deprecations(self, index=None, params=None): """ - ``_ + ``_ :arg index: Index pattern """ diff --git a/elasticsearch/client/ml.py b/elasticsearch/client/ml.py index 5b919edf..16a9de76 100644 --- a/elasticsearch/client/ml.py +++ b/elasticsearch/client/ml.py @@ -9,15 +9,16 @@ class MlClient(NamespacedClient): :arg job_id: The name of the job to close :arg body: The URL params optionally sent in the body - :arg allow_no_jobs: Whether to ignore if a wildcard expression matches - no jobs. (This includes `_all` string or when no jobs have been + :arg allow_no_jobs: Whether to ignore if a wildcard expression + matches no jobs. (This includes `_all` string or when no jobs have been specified) :arg force: True if the job should be forcefully closed - :arg timeout: Controls the time to wait until a job has closed. Default - to 30 minutes + :arg timeout: Controls the time to wait until a job has closed. + Default to 30 minutes """ if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'job_id'.") + return self.transport.perform_request( "POST", _make_path("_ml", "anomaly_detectors", job_id, "_close"), @@ -28,7 +29,10 @@ class MlClient(NamespacedClient): @query_params() def delete_calendar(self, calendar_id, params=None): """ - `<>`_ + :arg calendar_id: The ID of the calendar to delete :arg calendar_id: + The ID of the calendar to delete :arg calendar_id: The ID of the + calendar to delete :arg calendar_id: The ID of the calendar to delete + :arg calendar_id: The ID of the calendar to delete :arg calendar_id: The ID of the calendar to delete """ @@ -36,6 +40,7 @@ class MlClient(NamespacedClient): raise ValueError( "Empty value passed for a required argument 'calendar_id'." ) + return self.transport.perform_request( "DELETE", _make_path("_ml", "calendars", calendar_id), params=params ) @@ -43,7 +48,15 @@ class MlClient(NamespacedClient): @query_params() def delete_calendar_event(self, calendar_id, event_id, params=None): """ - `<>`_ + :arg calendar_id: The ID of the calendar to modify :arg event_id: The + ID of the event to remove from the calendar :arg calendar_id: The ID + of the calendar to modify :arg event_id: The ID of the event to remove + from the calendar :arg calendar_id: The ID of the calendar to modify + :arg event_id: The ID of the event to remove from the calendar :arg + calendar_id: The ID of the calendar to modify :arg event_id: The ID of + the event to remove from the calendar :arg calendar_id: The ID of the + calendar to modify :arg event_id: The ID of the event to remove from + the calendar :arg calendar_id: The ID of the calendar to modify :arg event_id: The ID of the event to remove from the calendar @@ -51,6 +64,7 @@ class MlClient(NamespacedClient): for param in (calendar_id, event_id): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "DELETE", _make_path("_ml", "calendars", calendar_id, "events", event_id), @@ -60,7 +74,15 @@ class MlClient(NamespacedClient): @query_params() def delete_calendar_job(self, calendar_id, job_id, params=None): """ - `<>`_ + :arg calendar_id: The ID of the calendar to modify :arg job_id: The ID + of the job to remove from the calendar :arg calendar_id: The ID of the + calendar to modify :arg job_id: The ID of the job to remove from the + calendar :arg calendar_id: The ID of the calendar to modify + :arg job_id: The ID of the job to remove from the calendar :arg + calendar_id: The ID of the calendar to modify :arg job_id: The ID of + the job to remove from the calendar :arg calendar_id: The ID of the + calendar to modify :arg job_id: The ID of the job to remove from the + calendar :arg calendar_id: The ID of the calendar to modify :arg job_id: The ID of the job to remove from the calendar @@ -68,6 +90,7 @@ class MlClient(NamespacedClient): for param in (calendar_id, job_id): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "DELETE", _make_path("_ml", "calendars", calendar_id, "jobs", job_id), @@ -86,6 +109,7 @@ class MlClient(NamespacedClient): raise ValueError( "Empty value passed for a required argument 'datafeed_id'." ) + return self.transport.perform_request( "DELETE", _make_path("_ml", "datafeeds", datafeed_id), params=params ) @@ -93,7 +117,7 @@ class MlClient(NamespacedClient): @query_params() def delete_expired_data(self, params=None): """ - `<>`_ + """ return self.transport.perform_request( "DELETE", "/_ml/_delete_expired_data", params=params @@ -102,12 +126,16 @@ class MlClient(NamespacedClient): @query_params() def delete_filter(self, filter_id, params=None): """ - `<>`_ + :arg filter_id: The ID of the filter to delete :arg filter_id: The ID + of the filter to delete :arg filter_id: The ID of the filter to delete + :arg filter_id: The ID of the filter to delete :arg filter_id: The ID + of the filter to delete :arg filter_id: The ID of the filter to delete """ if filter_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'filter_id'.") + return self.transport.perform_request( "DELETE", _make_path("_ml", "filters", filter_id), params=params ) @@ -122,11 +150,12 @@ class MlClient(NamespacedClient): delimited list. Leaving blank implies `_all` :arg allow_no_forecasts: Whether to ignore if `_all` matches no forecasts - :arg timeout: Controls the time to wait until the forecast(s) are - deleted. Default to 30 seconds + :arg timeout: Controls the time to wait until the forecast(s) + are deleted. Default to 30 seconds """ if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'job_id'.") + return self.transport.perform_request( "DELETE", _make_path("_ml", "anomaly_detectors", job_id, "_forecast", forecast_id), @@ -139,12 +168,13 @@ class MlClient(NamespacedClient): ``_ :arg job_id: The ID of the job to delete - :arg force: True if the job should be forcefully deleted, default False - :arg wait_for_completion: Should this request wait until the operation - has completed before returning, default True + :arg force: True if the job should be forcefully deleted + :arg wait_for_completion: Should this request wait until the + operation has completed before returning Default: True """ if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'job_id'.") + return self.transport.perform_request( "DELETE", _make_path("_ml", "anomaly_detectors", job_id), params=params ) @@ -160,6 +190,7 @@ class MlClient(NamespacedClient): for param in (job_id, snapshot_id): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "DELETE", _make_path( @@ -176,6 +207,7 @@ class MlClient(NamespacedClient): "format", "grok_pattern", "has_header_row", + "line_merge_size_limit", "lines_to_sample", "quote", "should_trim_fields", @@ -185,46 +217,47 @@ class MlClient(NamespacedClient): ) def find_file_structure(self, body, params=None): """ - ``_ + ``_ :arg body: The contents of the file to be analyzed - :arg charset: Optional parameter to specify the character set of the - file - :arg column_names: Optional parameter containing a comma separated list - of the column names for a delimited file - :arg delimiter: Optional parameter to specify the delimiter character + :arg charset: Optional parameter to specify the character set of + the file + :arg column_names: Optional parameter containing a comma + separated list of the column names for a delimited file + :arg delimiter: Optional parameter to specify the delimiter + character for a delimited file - must be a single character + :arg explain: Whether to include a commentary on how the + structure was derived + :arg format: Optional parameter to specify the high level file + format Valid choices: ndjson, xml, delimited, semi_structured_text + :arg grok_pattern: Optional parameter to specify the Grok + pattern that should be used to extract fields from messages in a semi- + structured text file + :arg has_header_row: Optional parameter to specify whether a + delimited file includes the column names in its first row + :arg line_merge_size_limit: Maximum number of characters + permitted in a single message when lines are merged to create messages. + Default: 10000 + :arg lines_to_sample: How many lines of the file should be + included in the analysis Default: 1000 + :arg quote: Optional parameter to specify the quote character for a delimited file - must be a single character - :arg explain: Whether to include a commentary on how the structure was - derived, default False - :arg format: Optional parameter to specify the high level file format, - valid choices are: 'ndjson', 'xml', 'delimited', - 'semi_structured_text' - :arg grok_pattern: Optional parameter to specify the Grok pattern that - should be used to extract fields from messages in a semi-structured - text file - :arg has_header_row: Optional parameter to specify whether a delimited - file includes the column names in its first row - :arg lines_to_sample: How many lines of the file should be included in - the analysis, default 1000 - :arg quote: Optional parameter to specify the quote character for a - delimited file - must be a single character - :arg should_trim_fields: Optional parameter to specify whether the - values between delimiters in a delimited file should have whitespace + :arg should_trim_fields: Optional parameter to specify whether + the values between delimiters in a delimited file should have whitespace trimmed from them - :arg timeout: Timeout after which the analysis will be aborted, default - '25s' - :arg timestamp_field: Optional parameter to specify the timestamp field - in the file - :arg timestamp_format: Optional parameter to specify the timestamp - format in the file - may be either a Joda or Java time format + :arg timeout: Timeout after which the analysis will be aborted + Default: 25s + :arg timestamp_field: Optional parameter to specify the + timestamp field in the file + :arg timestamp_format: Optional parameter to specify the + timestamp format in the file - may be either a Joda or Java time format """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + + body = self._bulk_body(body) return self.transport.perform_request( - "POST", - "/_ml/find_file_structure", - params=params, - body=self.client._bulk_body(body), + "POST", "/_ml/find_file_structure", params=params, body=body ) @query_params("advance_time", "calc_interim", "end", "skip_time", "start") @@ -234,19 +267,20 @@ class MlClient(NamespacedClient): :arg job_id: The name of the job to flush :arg body: Flush parameters - :arg advance_time: Advances time to the given value generating results - and updating the model for the advanced interval - :arg calc_interim: Calculates interim results for the most recent bucket - or all buckets within the latency period - :arg end: When used in conjunction with calc_interim, specifies the - range of buckets on which to calculate interim results - :arg skip_time: Skips time to the given value without generating results - or updating the model for the skipped interval - :arg start: When used in conjunction with calc_interim, specifies the - range of buckets on which to calculate interim results + :arg advance_time: Advances time to the given value generating + results and updating the model for the advanced interval + :arg calc_interim: Calculates interim results for the most + recent bucket or all buckets within the latency period + :arg end: When used in conjunction with calc_interim, specifies + the range of buckets on which to calculate interim results + :arg skip_time: Skips time to the given value without generating + results or updating the model for the skipped interval + :arg start: When used in conjunction with calc_interim, + specifies the range of buckets on which to calculate interim results """ if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'job_id'.") + return self.transport.perform_request( "POST", _make_path("_ml", "anomaly_detectors", job_id, "_flush"), @@ -257,15 +291,32 @@ class MlClient(NamespacedClient): @query_params("duration", "expires_in") def forecast(self, job_id, params=None): """ - `<>`_ + :arg job_id: The ID of the job to forecast for :arg duration: The + duration of the forecast :arg expires_in: The time interval after which + the forecast expires. Expired forecasts will be deleted at the + first opportunity. :arg job_id: The ID of the job to forecast for + :arg duration: The duration of the forecast :arg expires_in: The time + interval after which the forecast expires. Expired forecasts will + be deleted at the first opportunity. :arg job_id: The ID of the job to + forecast for :arg duration: The duration of the forecast :arg + expires_in: The time interval after which the forecast expires. + Expired forecasts will be deleted at the first opportunity. :arg + job_id: The ID of the job to forecast for :arg duration: The duration + of the forecast :arg expires_in: The time interval after which the + forecast expires. Expired forecasts will be deleted at the first + opportunity. :arg job_id: The ID of the job to forecast for + :arg duration: The duration of the forecast :arg expires_in: The time + interval after which the forecast expires. Expired forecasts will + be deleted at the first opportunity. :arg job_id: The ID of the job to forecast for :arg duration: The duration of the forecast - :arg expires_in: The time interval after which the forecast expires. - Expired forecasts will be deleted at the first opportunity. + :arg expires_in: The time interval after which the forecast + expires. Expired forecasts will be deleted at the first opportunity. """ if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'job_id'.") + return self.transport.perform_request( "POST", _make_path("_ml", "anomaly_detectors", job_id, "_forecast"), @@ -283,13 +334,14 @@ class MlClient(NamespacedClient): "sort", "start", ) - def get_buckets(self, job_id, timestamp=None, body=None, params=None): + def get_buckets(self, job_id, body=None, timestamp=None, params=None): """ ``_ :arg job_id: ID of the job to get bucket results from - :arg timestamp: The timestamp of the desired single bucket result :arg body: Bucket selection details if not provided in URI + :arg timestamp: The timestamp of the desired single bucket + result :arg anomaly_score: Filter for the most anomalous buckets :arg desc: Set the sort direction :arg end: End time filter for buckets @@ -300,8 +352,13 @@ class MlClient(NamespacedClient): :arg sort: Sort buckets by a particular field :arg start: Start time filter for buckets """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'job_id'.") + return self.transport.perform_request( "GET", _make_path( @@ -314,7 +371,31 @@ class MlClient(NamespacedClient): @query_params("end", "from_", "job_id", "size", "start") def get_calendar_events(self, calendar_id, params=None): """ - `<>`_ + :arg calendar_id: The ID of the calendar containing the events :arg + end: Get events before this time :arg from_: Skips a number of events + :arg job_id: Get events for the job. When this option is used + calendar_id must be '_all' :arg size: Specifies a max number of events + to get :arg start: Get events after this time :arg + calendar_id: The ID of the calendar containing the events :arg end: Get + events before this time :arg from_: Skips a number of events + :arg job_id: Get events for the job. When this option is used + calendar_id must be '_all' :arg size: Specifies a max number of events + to get :arg start: Get events after this time :arg + calendar_id: The ID of the calendar containing the events :arg end: Get + events before this time :arg from_: Skips a number of events + :arg job_id: Get events for the job. When this option is used + calendar_id must be '_all' :arg size: Specifies a max number of events + to get :arg start: Get events after this time :arg + calendar_id: The ID of the calendar containing the events :arg end: Get + events before this time :arg from_: Skips a number of events + :arg job_id: Get events for the job. When this option is used + calendar_id must be '_all' :arg size: Specifies a max number of events + to get :arg start: Get events after this time :arg + calendar_id: The ID of the calendar containing the events :arg end: Get + events before this time :arg from_: Skips a number of events + :arg job_id: Get events for the job. When this option is used + calendar_id must be '_all' :arg size: Specifies a max number of events + to get :arg start: Get events after this time :arg calendar_id: The ID of the calendar containing the events :arg end: Get events before this time @@ -324,41 +405,73 @@ class MlClient(NamespacedClient): :arg size: Specifies a max number of events to get :arg start: Get events after this time """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + if calendar_id in SKIP_IN_PATH: raise ValueError( "Empty value passed for a required argument 'calendar_id'." ) + return self.transport.perform_request( "GET", _make_path("_ml", "calendars", calendar_id, "events"), params=params ) @query_params("from_", "size") - def get_calendars(self, calendar_id=None, body=None, params=None): + def get_calendars(self, body=None, calendar_id=None, params=None): """ - `<>`_ + :arg body: The from and size parameters optionally sent in the body + :arg calendar_id: The ID of the calendar to fetch :arg from_: skips a + number of calendars :arg size: specifies a max number of calendars to + get :arg body: The from and size parameters optionally sent in the + body :arg calendar_id: The ID of the calendar to fetch :arg + from_: skips a number of calendars :arg size: specifies a max number of + calendars to get :arg body: The from and size parameters optionally + sent in the body :arg calendar_id: The ID of the calendar + to fetch :arg from_: skips a number of calendars :arg size: + specifies a max number of calendars to get :arg body: The from and + size parameters optionally sent in the body :arg + calendar_id: The ID of the calendar to fetch :arg from_: skips a number + of calendars :arg size: specifies a max number of calendars to get + :arg body: The from and size parameters optionally sent in the body + :arg calendar_id: The ID of the calendar to fetch :arg from_: skips a + number of calendars :arg size: specifies a max number of calendars to + get + :arg body: The from and size parameters optionally sent in the + body :arg calendar_id: The ID of the calendar to fetch - :arg body: The from and size parameters optionally sent in the body :arg from_: skips a number of calendars :arg size: specifies a max number of calendars to get """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + return self.transport.perform_request( "GET", _make_path("_ml", "calendars", calendar_id), params=params, body=body ) @query_params("from_", "size") - def get_categories(self, job_id, category_id=None, body=None, params=None): + def get_categories(self, job_id, body=None, category_id=None, params=None): """ ``_ :arg job_id: The name of the job - :arg category_id: The identifier of the category definition of interest :arg body: Category selection details if not provided in URI + :arg category_id: The identifier of the category definition of + interest :arg from_: skips a number of categories :arg size: specifies a max number of categories to get """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'job_id'.") + return self.transport.perform_request( "GET", _make_path( @@ -374,8 +487,8 @@ class MlClient(NamespacedClient): ``_ :arg datafeed_id: The ID of the datafeeds stats to fetch - :arg allow_no_datafeeds: Whether to ignore if a wildcard expression - matches no datafeeds. (This includes `_all` string or when no + :arg allow_no_datafeeds: Whether to ignore if a wildcard + expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) """ return self.transport.perform_request( @@ -388,8 +501,8 @@ class MlClient(NamespacedClient): ``_ :arg datafeed_id: The ID of the datafeeds to fetch - :arg allow_no_datafeeds: Whether to ignore if a wildcard expression - matches no datafeeds. (This includes `_all` string or when no + :arg allow_no_datafeeds: Whether to ignore if a wildcard + expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) """ return self.transport.perform_request( @@ -399,12 +512,25 @@ class MlClient(NamespacedClient): @query_params("from_", "size") def get_filters(self, filter_id=None, params=None): """ - `<>`_ + :arg filter_id: The ID of the filter to fetch :arg from_: skips a + number of filters :arg size: specifies a max number of filters to get + :arg filter_id: The ID of the filter to fetch :arg from_: skips a + number of filters :arg size: specifies a max number of filters to get + :arg filter_id: The ID of the filter to fetch :arg from_: skips a + number of filters :arg size: specifies a max number of filters to get + :arg filter_id: The ID of the filter to fetch :arg from_: skips a + number of filters :arg size: specifies a max number of filters to get + :arg filter_id: The ID of the filter to fetch :arg from_: skips a + number of filters :arg size: specifies a max number of filters to get :arg filter_id: The ID of the filter to fetch :arg from_: skips a number of filters :arg size: specifies a max number of filters to get """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + return self.transport.perform_request( "GET", _make_path("_ml", "filters", filter_id), params=params ) @@ -423,20 +549,26 @@ class MlClient(NamespacedClient): """ ``_ - :arg job_id: None + :arg job_id: :arg body: Influencer selection criteria - :arg desc: whether the results should be sorted in decending order + :arg desc: whether the results should be sorted in decending + order :arg end: end timestamp for the requested influencers :arg exclude_interim: Exclude interim results :arg from_: skips a number of influencers - :arg influencer_score: influencer score threshold for the requested - influencers + :arg influencer_score: influencer score threshold for the + requested influencers :arg size: specifies a max number of influencers to get :arg sort: sort field for the requested influencers :arg start: start timestamp for the requested influencers """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'job_id'.") + return self.transport.perform_request( "GET", _make_path("_ml", "anomaly_detectors", job_id, "results", "influencers"), @@ -450,8 +582,8 @@ class MlClient(NamespacedClient): ``_ :arg job_id: The ID of the jobs stats to fetch - :arg allow_no_jobs: Whether to ignore if a wildcard expression matches - no jobs. (This includes `_all` string or when no jobs have been + :arg allow_no_jobs: Whether to ignore if a wildcard expression + matches no jobs. (This includes `_all` string or when no jobs have been specified) """ return self.transport.perform_request( @@ -466,8 +598,8 @@ class MlClient(NamespacedClient): ``_ :arg job_id: The ID of the jobs to fetch - :arg allow_no_jobs: Whether to ignore if a wildcard expression matches - no jobs. (This includes `_all` string or when no jobs have been + :arg allow_no_jobs: Whether to ignore if a wildcard expression + matches no jobs. (This includes `_all` string or when no jobs have been specified) """ return self.transport.perform_request( @@ -475,23 +607,29 @@ class MlClient(NamespacedClient): ) @query_params("desc", "end", "from_", "size", "sort", "start") - def get_model_snapshots(self, job_id, snapshot_id=None, body=None, params=None): + def get_model_snapshots(self, job_id, body=None, snapshot_id=None, params=None): """ ``_ :arg job_id: The ID of the job to fetch - :arg snapshot_id: The ID of the snapshot to fetch :arg body: Model snapshot selection criteria - :arg desc: True if the results should be sorted in descending order + :arg snapshot_id: The ID of the snapshot to fetch + :arg desc: True if the results should be sorted in descending + order :arg end: The filter 'end' query parameter :arg from_: Skips a number of documents - :arg size: The default number of documents returned in queries as a - string. + :arg size: The default number of documents returned in queries + as a string. :arg sort: Name of the field to sort on :arg start: The filter 'start' query parameter """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'job_id'.") + return self.transport.perform_request( "GET", _make_path( @@ -514,24 +652,29 @@ class MlClient(NamespacedClient): """ ``_ - :arg job_id: The job IDs for which to calculate overall bucket results - :arg body: Overall bucket selection details if not provided in URI - :arg allow_no_jobs: Whether to ignore if a wildcard expression matches - no jobs. (This includes `_all` string or when no jobs have been + :arg job_id: The job IDs for which to calculate overall bucket + results + :arg body: Overall bucket selection details if not provided in + URI + :arg allow_no_jobs: Whether to ignore if a wildcard expression + matches no jobs. (This includes `_all` string or when no jobs have been specified) - :arg bucket_span: The span of the overall buckets. Defaults to the - longest job bucket_span - :arg end: Returns overall buckets with timestamps earlier than this time - :arg exclude_interim: If true overall buckets that include interim - buckets will be excluded - :arg overall_score: Returns overall buckets with overall scores higher - than this value - :arg start: Returns overall buckets with timestamps after this time - :arg top_n: The number of top job bucket scores to be used in the - overall_score calculation + :arg bucket_span: The span of the overall buckets. Defaults to + the longest job bucket_span + :arg end: Returns overall buckets with timestamps earlier than + this time + :arg exclude_interim: If true overall buckets that include + interim buckets will be excluded + :arg overall_score: Returns overall buckets with overall scores + higher than this value + :arg start: Returns overall buckets with timestamps after this + time + :arg top_n: The number of top job bucket scores to be used in + the overall_score calculation """ if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'job_id'.") + return self.transport.perform_request( "GET", _make_path( @@ -555,7 +698,7 @@ class MlClient(NamespacedClient): """ ``_ - :arg job_id: None + :arg job_id: :arg body: Record selection criteria :arg desc: Set the sort direction :arg end: End time filter for records @@ -566,8 +709,13 @@ class MlClient(NamespacedClient): :arg sort: Sort records by a particular field :arg start: Start time filter for records """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'job_id'.") + return self.transport.perform_request( "GET", _make_path("_ml", "anomaly_detectors", job_id, "results", "records"), @@ -578,7 +726,7 @@ class MlClient(NamespacedClient): @query_params() def info(self, params=None): """ - `<>`_ + """ return self.transport.perform_request("GET", "/_ml/info", params=params) @@ -591,6 +739,7 @@ class MlClient(NamespacedClient): """ if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'job_id'.") + return self.transport.perform_request( "POST", _make_path("_ml", "anomaly_detectors", job_id, "_open"), @@ -600,7 +749,13 @@ class MlClient(NamespacedClient): @query_params() def post_calendar_events(self, calendar_id, body, params=None): """ - `<>`_ + :arg calendar_id: The ID of the calendar to modify :arg body: A list of + events :arg calendar_id: The ID of the calendar to modify :arg + body: A list of events :arg calendar_id: The ID of the calendar to + modify :arg body: A list of events :arg calendar_id: The ID of + the calendar to modify :arg body: A list of events :arg + calendar_id: The ID of the calendar to modify :arg body: A list of + events :arg calendar_id: The ID of the calendar to modify :arg body: A list of events @@ -608,6 +763,7 @@ class MlClient(NamespacedClient): for param in (calendar_id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "POST", _make_path("_ml", "calendars", calendar_id, "events"), @@ -622,19 +778,21 @@ class MlClient(NamespacedClient): :arg job_id: The name of the job receiving the data :arg body: The data to process - :arg reset_end: Optional parameter to specify the end of the bucket - resetting range - :arg reset_start: Optional parameter to specify the start of the bucket - resetting range + :arg reset_end: Optional parameter to specify the end of the + bucket resetting range + :arg reset_start: Optional parameter to specify the start of the + bucket resetting range """ for param in (job_id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + + body = self._bulk_body(body) return self.transport.perform_request( "POST", _make_path("_ml", "anomaly_detectors", job_id, "_data"), params=params, - body=self.client._bulk_body(body), + body=body, ) @query_params() @@ -648,6 +806,7 @@ class MlClient(NamespacedClient): raise ValueError( "Empty value passed for a required argument 'datafeed_id'." ) + return self.transport.perform_request( "GET", _make_path("_ml", "datafeeds", datafeed_id, "_preview"), @@ -657,7 +816,13 @@ class MlClient(NamespacedClient): @query_params() def put_calendar(self, calendar_id, body=None, params=None): """ - `<>`_ + :arg calendar_id: The ID of the calendar to create :arg body: The + calendar details :arg calendar_id: The ID of the calendar to create + :arg body: The calendar details :arg calendar_id: The ID of the + calendar to create :arg body: The calendar details :arg + calendar_id: The ID of the calendar to create :arg body: The calendar + details :arg calendar_id: The ID of the calendar to create + :arg body: The calendar details :arg calendar_id: The ID of the calendar to create :arg body: The calendar details @@ -666,6 +831,7 @@ class MlClient(NamespacedClient): raise ValueError( "Empty value passed for a required argument 'calendar_id'." ) + return self.transport.perform_request( "PUT", _make_path("_ml", "calendars", calendar_id), params=params, body=body ) @@ -673,7 +839,15 @@ class MlClient(NamespacedClient): @query_params() def put_calendar_job(self, calendar_id, job_id, params=None): """ - `<>`_ + :arg calendar_id: The ID of the calendar to modify :arg job_id: The ID + of the job to add to the calendar :arg calendar_id: The ID of the + calendar to modify :arg job_id: The ID of the job to add to the + calendar :arg calendar_id: The ID of the calendar to modify + :arg job_id: The ID of the job to add to the calendar :arg + calendar_id: The ID of the calendar to modify :arg job_id: The ID of + the job to add to the calendar :arg calendar_id: The ID of the + calendar to modify :arg job_id: The ID of the job to add to the + calendar :arg calendar_id: The ID of the calendar to modify :arg job_id: The ID of the job to add to the calendar @@ -681,6 +855,7 @@ class MlClient(NamespacedClient): for param in (calendar_id, job_id): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_ml", "calendars", calendar_id, "jobs", job_id), @@ -698,6 +873,7 @@ class MlClient(NamespacedClient): for param in (datafeed_id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_ml", "datafeeds", datafeed_id), params=params, body=body ) @@ -705,7 +881,12 @@ class MlClient(NamespacedClient): @query_params() def put_filter(self, filter_id, body, params=None): """ - `<>`_ + :arg filter_id: The ID of the filter to create :arg body: The filter + details :arg filter_id: The ID of the filter to create :arg + body: The filter details :arg filter_id: The ID of the filter to + create :arg body: The filter details :arg filter_id: The ID of + the filter to create :arg body: The filter details :arg + filter_id: The ID of the filter to create :arg body: The filter details :arg filter_id: The ID of the filter to create :arg body: The filter details @@ -713,6 +894,7 @@ class MlClient(NamespacedClient): for param in (filter_id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_ml", "filters", filter_id), params=params, body=body ) @@ -728,6 +910,7 @@ class MlClient(NamespacedClient): for param in (job_id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_ml", "anomaly_detectors", job_id), @@ -743,12 +926,13 @@ class MlClient(NamespacedClient): :arg job_id: The ID of the job to fetch :arg snapshot_id: The ID of the snapshot to revert to :arg body: Reversion options - :arg delete_intervening_results: Should we reset the results back to the - time of the snapshot? + :arg delete_intervening_results: Should we reset the results + back to the time of the snapshot? """ for param in (job_id, snapshot_id): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "POST", _make_path( @@ -768,8 +952,8 @@ class MlClient(NamespacedClient): """ ``_ - :arg enabled: Whether to enable upgrade_mode ML setting or not. Defaults - to false. + :arg enabled: Whether to enable upgrade_mode ML setting or not. + Defaults to false. :arg timeout: Controls the time to wait before action times out. Defaults to 30 seconds """ @@ -784,16 +968,17 @@ class MlClient(NamespacedClient): :arg datafeed_id: The ID of the datafeed to start :arg body: The start datafeed parameters - :arg end: The end time when the datafeed should stop. When not set, the - datafeed continues in real time + :arg end: The end time when the datafeed should stop. When not + set, the datafeed continues in real time :arg start: The start time from where the datafeed should begin - :arg timeout: Controls the time to wait until a datafeed has started. - Default to 20 seconds + :arg timeout: Controls the time to wait until a datafeed has + started. Default to 20 seconds """ if datafeed_id in SKIP_IN_PATH: raise ValueError( "Empty value passed for a required argument 'datafeed_id'." ) + return self.transport.perform_request( "POST", _make_path("_ml", "datafeeds", datafeed_id, "_start"), @@ -807,17 +992,18 @@ class MlClient(NamespacedClient): ``_ :arg datafeed_id: The ID of the datafeed to stop - :arg allow_no_datafeeds: Whether to ignore if a wildcard expression - matches no datafeeds. (This includes `_all` string or when no + :arg allow_no_datafeeds: Whether to ignore if a wildcard + expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) :arg force: True if the datafeed should be forcefully stopped. - :arg timeout: Controls the time to wait until a datafeed has stopped. - Default to 20 seconds + :arg timeout: Controls the time to wait until a datafeed has + stopped. Default to 20 seconds """ if datafeed_id in SKIP_IN_PATH: raise ValueError( "Empty value passed for a required argument 'datafeed_id'." ) + return self.transport.perform_request( "POST", _make_path("_ml", "datafeeds", datafeed_id, "_stop"), params=params ) @@ -833,6 +1019,7 @@ class MlClient(NamespacedClient): for param in (datafeed_id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "POST", _make_path("_ml", "datafeeds", datafeed_id, "_update"), @@ -843,7 +1030,12 @@ class MlClient(NamespacedClient): @query_params() def update_filter(self, filter_id, body, params=None): """ - `<>`_ + :arg filter_id: The ID of the filter to update :arg body: The filter + update :arg filter_id: The ID of the filter to update :arg + body: The filter update :arg filter_id: The ID of the filter to update + :arg body: The filter update :arg filter_id: The ID of the filter to + update :arg body: The filter update :arg filter_id: The ID of + the filter to update :arg body: The filter update :arg filter_id: The ID of the filter to update :arg body: The filter update @@ -851,6 +1043,7 @@ class MlClient(NamespacedClient): for param in (filter_id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "POST", _make_path("_ml", "filters", filter_id, "_update"), @@ -869,6 +1062,7 @@ class MlClient(NamespacedClient): for param in (job_id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "POST", _make_path("_ml", "anomaly_detectors", job_id, "_update"), @@ -888,6 +1082,7 @@ class MlClient(NamespacedClient): for param in (job_id, snapshot_id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "POST", _make_path( @@ -905,12 +1100,15 @@ class MlClient(NamespacedClient): @query_params() def validate(self, body, params=None): """ - `<>`_ + :arg body: The job config :arg body: The job config :arg + body: The job config :arg body: The job config :arg body: The + job config :arg body: The job config """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "POST", "/_ml/anomaly_detectors/_validate", params=params, body=body ) @@ -918,15 +1116,170 @@ class MlClient(NamespacedClient): @query_params() def validate_detector(self, body, params=None): """ - `<>`_ + :arg body: The detector :arg body: The detector :arg body: + The detector :arg body: The detector :arg body: The detector :arg body: The detector """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "POST", "/_ml/anomaly_detectors/_validate/detector", params=params, body=body, ) + + @query_params() + def delete_data_frame_analytics(self, id, params=None): + """ + ``_ + + :arg id: The ID of the data frame analytics to delete + """ + if id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'id'.") + + return self.transport.perform_request( + "DELETE", _make_path("_ml", "data_frame", "analytics", id), params=params + ) + + @query_params() + def estimate_memory_usage(self, body, params=None): + """ + ``_ + + :arg body: Memory usage estimation definition + """ + if body in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'body'.") + + return self.transport.perform_request( + "POST", + "/_ml/data_frame/analytics/_estimate_memory_usage", + params=params, + body=body, + ) + + @query_params() + def evaluate_data_frame(self, body, params=None): + """ + ``_ + + :arg body: The evaluation definition + """ + if body in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'body'.") + + return self.transport.perform_request( + "POST", "/_ml/data_frame/_evaluate", params=params, body=body + ) + + @query_params("allow_no_match", "from_", "size") + def get_data_frame_analytics(self, id=None, params=None): + """ + ``_ + + :arg id: The ID of the data frame analytics to fetch + :arg allow_no_match: Whether to ignore if a wildcard expression + matches no data frame analytics. (This includes `_all` string or when no + data frame analytics have been specified) Default: True + :arg from_: skips a number of analytics + :arg size: specifies a max number of analytics to get Default: + 100 + """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + + return self.transport.perform_request( + "GET", _make_path("_ml", "data_frame", "analytics", id), params=params + ) + + @query_params("allow_no_match", "from_", "size") + def get_data_frame_analytics_stats(self, id=None, params=None): + """ + ``_ + + :arg id: The ID of the data frame analytics stats to fetch + :arg allow_no_match: Whether to ignore if a wildcard expression + matches no data frame analytics. (This includes `_all` string or when no + data frame analytics have been specified) Default: True + :arg from_: skips a number of analytics + :arg size: specifies a max number of analytics to get Default: + 100 + """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + + return self.transport.perform_request( + "GET", + _make_path("_ml", "data_frame", "analytics", id, "_stats"), + params=params, + ) + + @query_params() + def put_data_frame_analytics(self, id, body, params=None): + """ + ``_ + + :arg id: The ID of the data frame analytics to create + :arg body: The data frame analytics configuration + """ + for param in (id, body): + if param in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument.") + + return self.transport.perform_request( + "PUT", + _make_path("_ml", "data_frame", "analytics", id), + params=params, + body=body, + ) + + @query_params("timeout") + def start_data_frame_analytics(self, id, body=None, params=None): + """ + ``_ + + :arg id: The ID of the data frame analytics to start + :arg body: The start data frame analytics parameters + :arg timeout: Controls the time to wait until the task has + started. Defaults to 20 seconds + """ + if id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'id'.") + + return self.transport.perform_request( + "POST", + _make_path("_ml", "data_frame", "analytics", id, "_start"), + params=params, + body=body, + ) + + @query_params("allow_no_match", "force", "timeout") + def stop_data_frame_analytics(self, id, body=None, params=None): + """ + ``_ + + :arg id: The ID of the data frame analytics to stop + :arg body: The stop data frame analytics parameters + :arg allow_no_match: Whether to ignore if a wildcard expression + matches no data frame analytics. (This includes `_all` string or when no + data frame analytics have been specified) + :arg force: True if the data frame analytics should be + forcefully stopped + :arg timeout: Controls the time to wait until the task has + stopped. Defaults to 20 seconds + """ + if id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'id'.") + + return self.transport.perform_request( + "POST", + _make_path("_ml", "data_frame", "analytics", id, "_stop"), + params=params, + body=body, + ) diff --git a/elasticsearch/client/monitoring.py b/elasticsearch/client/monitoring.py index 09086ab0..87bfea5c 100644 --- a/elasticsearch/client/monitoring.py +++ b/elasticsearch/client/monitoring.py @@ -5,21 +5,24 @@ class MonitoringClient(NamespacedClient): @query_params("interval", "system_api_version", "system_id") def bulk(self, body, doc_type=None, params=None): """ - ``_ + ``_ - :arg body: The operation definition and data (action-data pairs), - separated by newlines - :arg doc_type: Default document type for items which don't provide one - :arg interval: Collection interval (e.g., '10s' or '10000ms') of the - payload + :arg body: The operation definition and data (action-data + pairs), separated by newlines + :arg doc_type: Default document type for items which don't + provide one + :arg interval: Collection interval (e.g., '10s' or '10000ms') of + the payload :arg system_api_version: API Version of the monitored system :arg system_id: Identifier of the monitored system """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + + body = self._bulk_body(body) return self.transport.perform_request( "POST", _make_path("_monitoring", doc_type, "bulk"), params=params, - body=self._bulk_body(body), + body=body, ) diff --git a/elasticsearch/client/nodes.py b/elasticsearch/client/nodes.py index 9549f062..18578861 100644 --- a/elasticsearch/client/nodes.py +++ b/elasticsearch/client/nodes.py @@ -5,32 +5,35 @@ class NodesClient(NamespacedClient): @query_params("timeout") def reload_secure_settings(self, node_id=None, params=None): """ - Reload any settings that have been marked as "reloadable" - ``_ + Reloads secure settings. + ``_ :arg node_id: A comma-separated list of node IDs to span the - reload/reinit call. Should stay empty because reloading usually - involves all cluster nodes. + reload/reinit call. Should stay empty because reloading usually involves + all cluster nodes. :arg timeout: Explicit operation timeout """ return self.transport.perform_request( - "POST", _make_path("_nodes", "reload_secure_settings"), params=params + "POST", + _make_path("_nodes", node_id, "reload_secure_settings"), + params=params, ) @query_params("flat_settings", "timeout") def info(self, node_id=None, metric=None, params=None): """ - The cluster nodes info API allows to retrieve one or more (or all) of - the cluster nodes information. - ``_ + Returns information about nodes in the cluster. + ``_ - :arg node_id: A comma-separated list of node IDs or names to limit the - returned information; use `_local` to return information from the - node you're connecting to, leave empty to get information from all + :arg node_id: A comma-separated list of node IDs or names to + limit the returned information; use `_local` to return information from + the node you're connecting to, leave empty to get information from all nodes - :arg metric: A comma-separated list of metrics you wish returned. Leave - empty to return all. - :arg flat_settings: Return settings in flat format (default: false) + :arg metric: A comma-separated list of metrics you wish + returned. Leave empty to return all. Valid choices: settings, os, + process, jvm, thread_pool, transport, http, plugins, ingest + :arg flat_settings: Return settings in flat format (default: + false) :arg timeout: Explicit operation timeout """ return self.transport.perform_request( @@ -49,35 +52,37 @@ class NodesClient(NamespacedClient): ) def stats(self, node_id=None, metric=None, index_metric=None, params=None): """ - The cluster nodes stats API allows to retrieve one or more (or all) of - the cluster nodes statistics. - ``_ + Returns statistical information about nodes in the cluster. + ``_ - :arg node_id: A comma-separated list of node IDs or names to limit the - returned information; use `_local` to return information from the - node you're connecting to, leave empty to get information from all + :arg node_id: A comma-separated list of node IDs or names to + limit the returned information; use `_local` to return information from + the node you're connecting to, leave empty to get information from all nodes - :arg metric: Limit the information returned to the specified metrics - :arg index_metric: Limit the information returned for `indices` metric - to the specific index metrics. Isn't used if `indices` (or `all`) - metric isn't specified. - :arg completion_fields: A comma-separated list of fields for `fielddata` - and `suggest` index metric (supports wildcards) - :arg fielddata_fields: A comma-separated list of fields for `fielddata` - index metric (supports wildcards) - :arg fields: A comma-separated list of fields for `fielddata` and - `completion` index metric (supports wildcards) - :arg groups: A comma-separated list of search groups for `search` index - metric - :arg include_segment_file_sizes: Whether to report the aggregated disk - usage of each one of the Lucene index files (only applies if segment - stats are requested), default False - :arg level: Return indices stats aggregated at index, node or shard - level, default 'node', valid choices are: 'indices', 'node', - 'shards' + :arg metric: Limit the information returned to the specified + metrics Valid choices: _all, breaker, fs, http, indices, jvm, os, + process, thread_pool, transport, discovery + :arg index_metric: Limit the information returned for `indices` + metric to the specific index metrics. Isn't used if `indices` (or `all`) + metric isn't specified. Valid choices: _all, completion, docs, + fielddata, query_cache, flush, get, indexing, merge, request_cache, + refresh, search, segments, store, warmer, suggest + :arg completion_fields: A comma-separated list of fields for + `fielddata` and `suggest` index metric (supports wildcards) + :arg fielddata_fields: A comma-separated list of fields for + `fielddata` index metric (supports wildcards) + :arg fields: A comma-separated list of fields for `fielddata` + and `completion` index metric (supports wildcards) + :arg groups: A comma-separated list of search groups for + `search` index metric + :arg include_segment_file_sizes: Whether to report the + aggregated disk usage of each one of the Lucene index files (only + applies if segment stats are requested) + :arg level: Return indices stats aggregated at index, node or + shard level Valid choices: indices, node, shards Default: node :arg timeout: Explicit operation timeout - :arg types: A comma-separated list of document types for the `indexing` - index metric + :arg types: A comma-separated list of document types for the + `indexing` index metric """ return self.transport.perform_request( "GET", @@ -90,45 +95,45 @@ class NodesClient(NamespacedClient): ) def hot_threads(self, node_id=None, params=None): """ - An API allowing to get the current hot threads on each node in the cluster. - ``_ + Returns information about hot threads on each node in the cluster. + ``_ - :arg node_id: A comma-separated list of node IDs or names to limit the - returned information; use `_local` to return information from the - node you're connecting to, leave empty to get information from all + :arg node_id: A comma-separated list of node IDs or names to + limit the returned information; use `_local` to return information from + the node you're connecting to, leave empty to get information from all nodes - :arg type: The type to sample (default: cpu), valid choices are: - 'cpu', 'wait', 'block' - :arg ignore_idle_threads: Don't show threads that are in known-idle - places, such as waiting on a socket select or pulling from an empty + :arg doc_type: The type to sample (default: cpu) Valid choices: + cpu, wait, block + :arg ignore_idle_threads: Don't show threads that are in known- + idle places, such as waiting on a socket select or pulling from an empty task queue (default: true) :arg interval: The interval for the second sampling of threads - :arg snapshots: Number of samples of thread stacktrace (default: 10) - :arg threads: Specify the number of threads to provide information for - (default: 3) + :arg snapshots: Number of samples of thread stacktrace (default: + 10) + :arg threads: Specify the number of threads to provide + information for (default: 3) :arg timeout: Explicit operation timeout """ - # avoid python reserved words - if params and "type_" in params: - params["type"] = params.pop("type_") + # type is a reserved word so it cannot be used, use doc_type instead + if "doc_type" in params: + params["type"] = params.pop("doc_type") + return self.transport.perform_request( - "GET", _make_path("_cluster", "nodes", node_id, "hotthreads"), params=params + "GET", _make_path("_nodes", node_id, "hot_threads"), params=params ) - @query_params("human", "timeout") + @query_params("timeout") def usage(self, node_id=None, metric=None, params=None): """ - The cluster nodes usage API allows to retrieve information on the usage - of features for each node. - ``_ + Returns low-level information about REST actions usage on nodes. + ``_ - :arg node_id: A comma-separated list of node IDs or names to limit the - returned information; use `_local` to return information from the - node you're connecting to, leave empty to get information from all + :arg node_id: A comma-separated list of node IDs or names to + limit the returned information; use `_local` to return information from + the node you're connecting to, leave empty to get information from all nodes - :arg metric: Limit the information returned to the specified metrics - :arg human: Whether to return time and byte values in human-readable - format., default False + :arg metric: Limit the information returned to the specified + metrics Valid choices: _all, rest_actions :arg timeout: Explicit operation timeout """ return self.transport.perform_request( diff --git a/elasticsearch/client/rollup.py b/elasticsearch/client/rollup.py index ea82682c..612d0f96 100644 --- a/elasticsearch/client/rollup.py +++ b/elasticsearch/client/rollup.py @@ -5,12 +5,15 @@ class RollupClient(NamespacedClient): @query_params() def delete_job(self, id, params=None): """ - `<>`_ + :arg id: The ID of the job to delete :arg id: The ID of the job to + delete :arg id: The ID of the job to delete :arg id: The ID + of the job to delete :arg id: The ID of the job to delete :arg id: The ID of the job to delete """ if id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'id'.") + return self.transport.perform_request( "DELETE", _make_path("_rollup", "job", id), params=params ) @@ -18,10 +21,17 @@ class RollupClient(NamespacedClient): @query_params() def get_jobs(self, id=None, params=None): """ - `<>`_ + :arg id: The ID of the job(s) to fetch. Accepts glob patterns, or + left blank for all jobs :arg id: The ID of the job(s) to fetch. + Accepts glob patterns, or left blank for all jobs :arg id: + The ID of the job(s) to fetch. Accepts glob patterns, or left blank + for all jobs :arg id: The ID of the job(s) to fetch. Accepts glob + patterns, or left blank for all jobs :arg id: The ID of + the job(s) to fetch. Accepts glob patterns, or left blank for all + jobs - :arg id: The ID of the job(s) to fetch. Accepts glob patterns, or left - blank for all jobs + :arg id: The ID of the job(s) to fetch. Accepts glob patterns, + or left blank for all jobs """ return self.transport.perform_request( "GET", _make_path("_rollup", "job", id), params=params @@ -30,10 +40,16 @@ class RollupClient(NamespacedClient): @query_params() def get_rollup_caps(self, id=None, params=None): """ - `<>`_ + :arg id: The ID of the index to check rollup capabilities on, or left + blank for all jobs :arg id: The ID of the index to check rollup + capabilities on, or left blank for all jobs :arg id: The + ID of the index to check rollup capabilities on, or left blank for + all jobs :arg id: The ID of the index to check rollup capabilities on, + or left blank for all jobs :arg id: The ID of the index to + check rollup capabilities on, or left blank for all jobs - :arg id: The ID of the index to check rollup capabilities on, or left - blank for all jobs + :arg id: The ID of the index to check rollup capabilities on, or + left blank for all jobs """ return self.transport.perform_request( "GET", _make_path("_rollup", "data", id), params=params @@ -42,13 +58,20 @@ class RollupClient(NamespacedClient): @query_params() def get_rollup_index_caps(self, index, params=None): """ - `<>`_ + :arg index: The rollup index or index pattern to obtain rollup + capabilities from. :arg index: The rollup index or index pattern to + obtain rollup capabilities from. :arg index: The rollup + index or index pattern to obtain rollup capabilities from. + :arg index: The rollup index or index pattern to obtain rollup + capabilities from. :arg index: The rollup index or index pattern to + obtain rollup capabilities from. :arg index: The rollup index or index pattern to obtain rollup capabilities from. """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") + return self.transport.perform_request( "GET", _make_path(index, "_rollup", "data"), params=params ) @@ -56,7 +79,11 @@ class RollupClient(NamespacedClient): @query_params() def put_job(self, id, body, params=None): """ - `<>`_ + :arg id: The ID of the job to create :arg body: The job configuration + :arg id: The ID of the job to create :arg body: The job configuration + :arg id: The ID of the job to create :arg body: The job configuration + :arg id: The ID of the job to create :arg body: The job configuration + :arg id: The ID of the job to create :arg body: The job configuration :arg id: The ID of the job to create :arg body: The job configuration @@ -64,6 +91,7 @@ class RollupClient(NamespacedClient): for param in (id, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_rollup", "job", id), params=params, body=body ) @@ -71,21 +99,54 @@ class RollupClient(NamespacedClient): @query_params("rest_total_hits_as_int", "typed_keys") def rollup_search(self, index, body, doc_type=None, params=None): """ - `<>`_ + :arg index: The indices or index-pattern(s) (containing rollup or + regular data) that should be searched :arg body: The search request + body :arg doc_type: The doc type inside the index :arg + rest_total_hits_as_int: Indicates whether hits.total should be + rendered as an integer or an object in the rest search response :arg + typed_keys: Specify whether aggregation and suggester names should + be prefixed by their respective types in the response :arg index: The + indices or index-pattern(s) (containing rollup or regular data) + that should be searched :arg body: The search request body :arg + doc_type: The doc type inside the index :arg rest_total_hits_as_int: + Indicates whether hits.total should be rendered as an integer or an + object in the rest search response :arg typed_keys: Specify whether + aggregation and suggester names should be prefixed by their + respective types in the response :arg index: The indices or index- + pattern(s) (containing rollup or regular data) that should be + searched :arg body: The search request body :arg doc_type: The + doc type inside the index :arg rest_total_hits_as_int: Indicates + whether hits.total should be rendered as an integer or an object in + the rest search response :arg typed_keys: Specify whether aggregation + and suggester names should be prefixed by their respective types in + the response :arg index: The indices or index-pattern(s) (containing + rollup or regular data) that should be searched :arg body: + The search request body :arg doc_type: The doc type inside the index + :arg rest_total_hits_as_int: Indicates whether hits.total should be + rendered as an integer or an object in the rest search response :arg + typed_keys: Specify whether aggregation and suggester names should + be prefixed by their respective types in the response :arg index: The + indices or index-pattern(s) (containing rollup or regular data) + that should be searched :arg body: The search request body :arg + doc_type: The doc type inside the index :arg rest_total_hits_as_int: + Indicates whether hits.total should be rendered as an integer or an + object in the rest search response :arg typed_keys: Specify whether + aggregation and suggester names should be prefixed by their + respective types in the response - :arg index: The indices or index-pattern(s) (containing rollup or - regular data) that should be searched + :arg index: The indices or index-pattern(s) (containing rollup + or regular data) that should be searched :arg body: The search request body :arg doc_type: The doc type inside the index - :arg rest_total_hits_as_int: Indicates whether hits.total should be - rendered as an integer or an object in the rest search response, - default False - :arg typed_keys: Specify whether aggregation and suggester names should - be prefixed by their respective types in the response + :arg rest_total_hits_as_int: Indicates whether hits.total should + be rendered as an integer or an object in the rest search response + :arg typed_keys: Specify whether aggregation and suggester names + should be prefixed by their respective types in the response """ for param in (index, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "GET", _make_path(index, doc_type, "_rollup_search"), @@ -96,12 +157,15 @@ class RollupClient(NamespacedClient): @query_params() def start_job(self, id, params=None): """ - `<>`_ + :arg id: The ID of the job to start :arg id: The ID of the job to + start :arg id: The ID of the job to start :arg id: The ID of + the job to start :arg id: The ID of the job to start :arg id: The ID of the job to start """ if id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'id'.") + return self.transport.perform_request( "POST", _make_path("_rollup", "job", id, "_start"), params=params ) @@ -109,16 +173,40 @@ class RollupClient(NamespacedClient): @query_params("timeout", "wait_for_completion") def stop_job(self, id, params=None): """ - `<>`_ + :arg id: The ID of the job to stop :arg timeout: Block for (at maximum) + the specified duration while waiting for the job to stop. Defaults + to 30s. :arg wait_for_completion: True if the API should block until + the job has fully stopped, false if should be executed async. + Defaults to false. :arg id: The ID of the job to stop + :arg timeout: Block for (at maximum) the specified duration while + waiting for the job to stop. Defaults to 30s. :arg + wait_for_completion: True if the API should block until the job has + fully stopped, false if should be executed async. Defaults to false. + :arg id: The ID of the job to stop :arg timeout: Block for (at maximum) + the specified duration while waiting for the job to stop. Defaults + to 30s. :arg wait_for_completion: True if the API should block until + the job has fully stopped, false if should be executed async. + Defaults to false. :arg id: The ID of the job to stop + :arg timeout: Block for (at maximum) the specified duration while + waiting for the job to stop. Defaults to 30s. :arg + wait_for_completion: True if the API should block until the job has + fully stopped, false if should be executed async. Defaults to false. + :arg id: The ID of the job to stop :arg timeout: Block for (at maximum) + the specified duration while waiting for the job to stop. Defaults + to 30s. :arg wait_for_completion: True if the API should block until + the job has fully stopped, false if should be executed async. + Defaults to false. :arg id: The ID of the job to stop - :arg timeout: Block for (at maximum) the specified duration while - waiting for the job to stop. Defaults to 30s. - :arg wait_for_completion: True if the API should block until the job has - fully stopped, false if should be executed async. Defaults to false. + :arg timeout: Block for (at maximum) the specified duration + while waiting for the job to stop. Defaults to 30s. + :arg wait_for_completion: True if the API should block until the + job has fully stopped, false if should be executed async. Defaults to + false. """ if id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'id'.") + return self.transport.perform_request( "POST", _make_path("_rollup", "job", id, "_stop"), params=params ) diff --git a/elasticsearch/client/security.py b/elasticsearch/client/security.py index 5c43452e..ff546f96 100644 --- a/elasticsearch/client/security.py +++ b/elasticsearch/client/security.py @@ -6,6 +6,7 @@ class SecurityClient(NamespacedClient): def authenticate(self, params=None): """ ``_ + """ return self.transport.perform_request( "GET", "/_security/_authenticate", params=params @@ -17,15 +18,16 @@ class SecurityClient(NamespacedClient): ``_ :arg body: the new password for the user - :arg username: The username of the user to change the password for - :arg refresh: If `true` (the default) 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` - then do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg username: The username of the user to change the password + for + :arg refresh: If `true` (the default) 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` then + do nothing with refreshes. Valid choices: true, false, wait_for """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "PUT", _make_path("_security", "user", username, "_password"), @@ -39,11 +41,12 @@ class SecurityClient(NamespacedClient): ``_ :arg realms: Comma-separated list of realms to clear - :arg usernames: Comma-separated list of usernames to clear from the - cache + :arg usernames: Comma-separated list of usernames to clear from + the cache """ if realms in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'realms'.") + return self.transport.perform_request( "POST", _make_path("_security", "realm", realms, "_clear_cache"), @@ -59,6 +62,7 @@ class SecurityClient(NamespacedClient): """ if name in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'name'.") + return self.transport.perform_request( "POST", _make_path("_security", "role", name, "_clear_cache"), params=params ) @@ -69,14 +73,14 @@ class SecurityClient(NamespacedClient): ``_ :arg body: The api key request to create an API key - :arg refresh: If `true` (the default) 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` - then do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg refresh: If `true` (the default) 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` then + do nothing with refreshes. Valid choices: true, false, wait_for """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "PUT", "/_security/api_key", params=params, body=body ) @@ -88,15 +92,15 @@ class SecurityClient(NamespacedClient): :arg application: Application name :arg name: Privilege name - :arg refresh: If `true` (the default) 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` - then do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg refresh: If `true` (the default) 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` then + do nothing with refreshes. Valid choices: true, false, wait_for """ for param in (application, name): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "DELETE", _make_path("_security", "privilege", application, name), @@ -109,14 +113,14 @@ class SecurityClient(NamespacedClient): ``_ :arg name: Role name - :arg refresh: If `true` (the default) 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` - then do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg refresh: If `true` (the default) 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` then + do nothing with refreshes. Valid choices: true, false, wait_for """ if name in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'name'.") + return self.transport.perform_request( "DELETE", _make_path("_security", "role", name), params=params ) @@ -127,14 +131,14 @@ class SecurityClient(NamespacedClient): ``_ :arg name: Role-mapping name - :arg refresh: If `true` (the default) 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` - then do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg refresh: If `true` (the default) 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` then + do nothing with refreshes. Valid choices: true, false, wait_for """ if name in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'name'.") + return self.transport.perform_request( "DELETE", _make_path("_security", "role_mapping", name), params=params ) @@ -145,14 +149,14 @@ class SecurityClient(NamespacedClient): ``_ :arg username: username - :arg refresh: If `true` (the default) 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` - then do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg refresh: If `true` (the default) 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` then + do nothing with refreshes. Valid choices: true, false, wait_for """ if username in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'username'.") + return self.transport.perform_request( "DELETE", _make_path("_security", "user", username), params=params ) @@ -163,14 +167,14 @@ class SecurityClient(NamespacedClient): ``_ :arg username: The username of the user to disable - :arg refresh: If `true` (the default) 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` - then do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg refresh: If `true` (the default) 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` then + do nothing with refreshes. Valid choices: true, false, wait_for """ if username in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'username'.") + return self.transport.perform_request( "PUT", _make_path("_security", "user", username, "_disable"), params=params ) @@ -181,29 +185,31 @@ class SecurityClient(NamespacedClient): ``_ :arg username: The username of the user to enable - :arg refresh: If `true` (the default) 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` - then do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg refresh: If `true` (the default) 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` then + do nothing with refreshes. Valid choices: true, false, wait_for """ if username in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'username'.") + return self.transport.perform_request( "PUT", _make_path("_security", "user", username, "_enable"), params=params ) - @query_params("id", "name", "realm_name", "username") + @query_params("id", "name", "owner", "realm_name", "username") def get_api_key(self, params=None): """ ``_ :arg id: API key id of the API key to be retrieved :arg name: API key name of the API key to be retrieved - :arg realm_name: realm name of the user who created this API key to be - retrieved - :arg username: user name of the user who created this API key to be - retrieved + :arg owner: flag to query API keys owned by the currently + authenticated user + :arg realm_name: realm name of the user who created this API key + to be retrieved + :arg username: user name of the user who created this API key to + be retrieved """ return self.transport.perform_request( "GET", "/_security/api_key", params=params @@ -212,7 +218,7 @@ class SecurityClient(NamespacedClient): @query_params() def get_privileges(self, application=None, name=None, params=None): """ - ``_ + ``_ :arg application: Application name :arg name: Privilege name @@ -254,6 +260,7 @@ class SecurityClient(NamespacedClient): """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "POST", "/_security/oauth2/token", params=params, body=body ) @@ -272,7 +279,8 @@ class SecurityClient(NamespacedClient): @query_params() def get_user_privileges(self, params=None): """ - ``_ + ``_ + """ return self.transport.perform_request( "GET", "/_security/user/_privileges", params=params @@ -288,6 +296,7 @@ class SecurityClient(NamespacedClient): """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "GET", _make_path("_security", "user", user, "_has_privileges"), @@ -304,6 +313,7 @@ class SecurityClient(NamespacedClient): """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "DELETE", "/_security/api_key", params=params, body=body ) @@ -317,6 +327,7 @@ class SecurityClient(NamespacedClient): """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "DELETE", "/_security/oauth2/token", params=params, body=body ) @@ -327,14 +338,14 @@ class SecurityClient(NamespacedClient): ``_ :arg body: The privilege(s) to add - :arg refresh: If `true` (the default) 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` - then do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg refresh: If `true` (the default) 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` then + do nothing with refreshes. Valid choices: true, false, wait_for """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "PUT", "/_security/privilege/", params=params, body=body ) @@ -346,15 +357,15 @@ class SecurityClient(NamespacedClient): :arg name: Role name :arg body: The role to add - :arg refresh: If `true` (the default) 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` - then do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg refresh: If `true` (the default) 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` then + do nothing with refreshes. Valid choices: true, false, wait_for """ for param in (name, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_security", "role", name), params=params, body=body ) @@ -365,16 +376,16 @@ class SecurityClient(NamespacedClient): ``_ :arg name: Role-mapping name - :arg body: The role to add - :arg refresh: If `true` (the default) 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` - then do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg body: The role mapping to add + :arg refresh: If `true` (the default) 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` then + do nothing with refreshes. Valid choices: true, false, wait_for """ for param in (name, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_security", "role_mapping", name), @@ -389,15 +400,25 @@ class SecurityClient(NamespacedClient): :arg username: The username of the User :arg body: The user to add - :arg refresh: If `true` (the default) 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` - then do nothing with refreshes., valid choices are: 'true', 'false', - 'wait_for' + :arg refresh: If `true` (the default) 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` then + do nothing with refreshes. Valid choices: true, false, wait_for """ for param in (username, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_security", "user", username), params=params, body=body ) + + @query_params() + def get_builtin_privileges(self, params=None): + """ + ``_ + + """ + return self.transport.perform_request( + "GET", "/_security/privilege/_builtin", params=params + ) diff --git a/elasticsearch/client/slm.py b/elasticsearch/client/slm.py new file mode 100644 index 00000000..d09c2623 --- /dev/null +++ b/elasticsearch/client/slm.py @@ -0,0 +1,78 @@ +from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH + + +class SlmClient(NamespacedClient): + @query_params() + def delete_lifecycle(self, policy_id, params=None): + """ + ``_ + + :arg policy_id: The id of the snapshot lifecycle policy to + remove + """ + if policy_id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'policy_id'.") + + return self.transport.perform_request( + "DELETE", _make_path("_slm", "policy", policy_id), params=params + ) + + @query_params() + def execute_lifecycle(self, policy_id, params=None): + """ + ``_ + + :arg policy_id: The id of the snapshot lifecycle policy to be + executed + """ + if policy_id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'policy_id'.") + + return self.transport.perform_request( + "PUT", _make_path("_slm", "policy", policy_id, "_execute"), params=params + ) + + @query_params() + def execute_retention(self, params=None): + """ + ``_ + + """ + return self.transport.perform_request( + "POST", "/_slm/_execute_retention", params=params + ) + + @query_params() + def get_lifecycle(self, policy_id=None, params=None): + """ + ``_ + + :arg policy_id: Comma-separated list of snapshot lifecycle + policies to retrieve + """ + return self.transport.perform_request( + "GET", _make_path("_slm", "policy", policy_id), params=params + ) + + @query_params() + def get_stats(self, params=None): + """ + ``_ + + """ + return self.transport.perform_request("GET", "/_slm/stats", params=params) + + @query_params() + def put_lifecycle(self, policy_id, body=None, params=None): + """ + ``_ + + :arg policy_id: The id of the snapshot lifecycle policy + :arg body: The snapshot lifecycle policy definition to register + """ + if policy_id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'policy_id'.") + + return self.transport.perform_request( + "PUT", _make_path("_slm", "policy", policy_id), params=params, body=body + ) diff --git a/elasticsearch/client/snapshot.py b/elasticsearch/client/snapshot.py index 88aed52c..e7456e96 100644 --- a/elasticsearch/client/snapshot.py +++ b/elasticsearch/client/snapshot.py @@ -5,20 +5,21 @@ class SnapshotClient(NamespacedClient): @query_params("master_timeout", "wait_for_completion") def create(self, repository, snapshot, body=None, params=None): """ - Create a snapshot in repository - ``_ + Creates a snapshot in a repository. + ``_ :arg repository: A repository name :arg snapshot: A snapshot name :arg body: The snapshot definition - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg wait_for_completion: Should this request wait until the operation - has completed before returning, default False + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg wait_for_completion: Should this request wait until the + operation has completed before returning """ for param in (repository, snapshot): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_snapshot", repository, snapshot), @@ -29,17 +30,18 @@ class SnapshotClient(NamespacedClient): @query_params("master_timeout") def delete(self, repository, snapshot, params=None): """ - Deletes a snapshot from a repository. - ``_ + Deletes a snapshot. + ``_ :arg repository: A repository name :arg snapshot: A snapshot name - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg master_timeout: Explicit operation timeout for connection + to master node """ for param in (repository, snapshot): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "DELETE", _make_path("_snapshot", repository, snapshot), params=params ) @@ -47,21 +49,23 @@ class SnapshotClient(NamespacedClient): @query_params("ignore_unavailable", "master_timeout", "verbose") def get(self, repository, snapshot, params=None): """ - Retrieve information about a snapshot. - ``_ + Returns information about a snapshot. + ``_ :arg repository: A repository name :arg snapshot: A comma-separated list of snapshot names - :arg ignore_unavailable: Whether to ignore unavailable snapshots, - defaults to false which means a NotFoundError `snapshot_missing_exception` is thrown - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg verbose: Whether to show verbose snapshot info or only show the - basic info found in the repository index blob + :arg ignore_unavailable: Whether to ignore unavailable + snapshots, defaults to false which means a SnapshotMissingException is + thrown + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg verbose: Whether to show verbose snapshot info or only show + the basic info found in the repository index blob """ for param in (repository, snapshot): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "GET", _make_path("_snapshot", repository, snapshot), params=params ) @@ -69,16 +73,17 @@ class SnapshotClient(NamespacedClient): @query_params("master_timeout", "timeout") def delete_repository(self, repository, params=None): """ - Removes a shared file system repository. - ``_ + Deletes a repository. + ``_ :arg repository: A comma-separated list of repository names - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg master_timeout: Explicit operation timeout for connection + to master node :arg timeout: Explicit operation timeout """ if repository in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'repository'.") + return self.transport.perform_request( "DELETE", _make_path("_snapshot", repository), params=params ) @@ -86,14 +91,14 @@ class SnapshotClient(NamespacedClient): @query_params("local", "master_timeout") def get_repository(self, repository=None, params=None): """ - Return information about registered repositories. - ``_ + Returns information about a repository. + ``_ :arg repository: A comma-separated list of repository names - :arg local: Return local information, do not retrieve the state from - master node (default: false) - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg local: Return local information, do not retrieve the state + from master node (default: false) + :arg master_timeout: Explicit operation timeout for connection + to master node """ return self.transport.perform_request( "GET", _make_path("_snapshot", repository), params=params @@ -102,19 +107,20 @@ class SnapshotClient(NamespacedClient): @query_params("master_timeout", "timeout", "verify") def create_repository(self, repository, body, params=None): """ - Registers a shared file system repository. - ``_ + Creates a repository. + ``_ :arg repository: A repository name :arg body: The repository definition - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg master_timeout: Explicit operation timeout for connection + to master node :arg timeout: Explicit operation timeout :arg verify: Whether to verify the repository after creation """ for param in (repository, body): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "PUT", _make_path("_snapshot", repository), params=params, body=body ) @@ -122,20 +128,21 @@ class SnapshotClient(NamespacedClient): @query_params("master_timeout", "wait_for_completion") def restore(self, repository, snapshot, body=None, params=None): """ - Restore a snapshot. - ``_ + Restores a snapshot. + ``_ :arg repository: A repository name :arg snapshot: A snapshot name :arg body: Details of what to restore - :arg master_timeout: Explicit operation timeout for connection to master - node - :arg wait_for_completion: Should this request wait until the operation - has completed before returning, default False + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg wait_for_completion: Should this request wait until the + operation has completed before returning """ for param in (repository, snapshot): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") + return self.transport.perform_request( "POST", _make_path("_snapshot", repository, snapshot, "_restore"), @@ -146,17 +153,16 @@ class SnapshotClient(NamespacedClient): @query_params("ignore_unavailable", "master_timeout") def status(self, repository=None, snapshot=None, params=None): """ - Return information about all currently running snapshots. By specifying - a repository name, it's possible to limit the results to a particular - repository. - ``_ + Returns information about the status of a snapshot. + ``_ :arg repository: A repository name :arg snapshot: A comma-separated list of snapshot names - :arg ignore_unavailable: Whether to ignore unavailable snapshots, - defaults to false which means a NotFoundError `snapshot_missing_exception` is thrown - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg ignore_unavailable: Whether to ignore unavailable + snapshots, defaults to false which means a SnapshotMissingException is + thrown + :arg master_timeout: Explicit operation timeout for connection + to master node """ return self.transport.perform_request( "GET", @@ -167,17 +173,35 @@ class SnapshotClient(NamespacedClient): @query_params("master_timeout", "timeout") def verify_repository(self, repository, params=None): """ - Returns a list of nodes where repository was successfully verified or - an error message if verification process failed. - ``_ + Verifies a repository. + ``_ :arg repository: A repository name - :arg master_timeout: Explicit operation timeout for connection to master - node + :arg master_timeout: Explicit operation timeout for connection + to master node :arg timeout: Explicit operation timeout """ if repository in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'repository'.") + return self.transport.perform_request( "POST", _make_path("_snapshot", repository, "_verify"), params=params ) + + @query_params("master_timeout", "timeout") + def cleanup_repository(self, repository, params=None): + """ + Removes stale data from repository. + ``_ + + :arg repository: A repository name + :arg master_timeout: Explicit operation timeout for connection + to master node + :arg timeout: Explicit operation timeout + """ + if repository in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'repository'.") + + return self.transport.perform_request( + "POST", _make_path("_snapshot", repository, "_cleanup"), params=params + ) diff --git a/elasticsearch/client/sql.py b/elasticsearch/client/sql.py index e545228d..550d6c0e 100644 --- a/elasticsearch/client/sql.py +++ b/elasticsearch/client/sql.py @@ -7,11 +7,12 @@ class SqlClient(NamespacedClient): """ ``_ - :arg body: Specify the cursor value in the `cursor` element to clean the - cursor. + :arg body: Specify the cursor value in the `cursor` element to + clean the cursor. """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "POST", "/_sql/close", params=params, body=body ) @@ -21,12 +22,14 @@ class SqlClient(NamespacedClient): """ ``_ - :arg body: Use the `query` element to start a query. Use the `cursor` - element to continue a query. - :arg format: a short version of the Accept header, e.g. json, yaml + :arg body: Use the `query` element to start a query. Use the + `cursor` element to continue a query. + :arg format: a short version of the Accept header, e.g. json, + yaml """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request("POST", "/_sql", params=params, body=body) @query_params() @@ -38,6 +41,7 @@ class SqlClient(NamespacedClient): """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") + return self.transport.perform_request( "POST", "/_sql/translate", params=params, body=body ) diff --git a/elasticsearch/client/ssl.py b/elasticsearch/client/ssl.py index 64cce183..1003a29e 100644 --- a/elasticsearch/client/ssl.py +++ b/elasticsearch/client/ssl.py @@ -6,6 +6,7 @@ class SslClient(NamespacedClient): def certificates(self, params=None): """ ``_ + """ return self.transport.perform_request( "GET", "/_ssl/certificates", params=params diff --git a/elasticsearch/client/tasks.py b/elasticsearch/client/tasks.py index d98d3bbd..b38f1268 100644 --- a/elasticsearch/client/tasks.py +++ b/elasticsearch/client/tasks.py @@ -8,44 +8,43 @@ class TasksClient(NamespacedClient): "group_by", "nodes", "parent_task_id", - "wait_for_completion", "timeout", + "wait_for_completion", ) def list(self, params=None): """ - ``_ + Returns a list of tasks. + ``_ - :arg actions: A comma-separated list of actions that should be returned. - Leave empty to return all. + :arg actions: A comma-separated list of actions that should be + returned. Leave empty to return all. :arg detailed: Return detailed task information (default: false) - :arg group_by: Group tasks by nodes or parent/child relationships, - default 'nodes', valid choices are: 'nodes', 'parents' - :arg nodes: A comma-separated list of node IDs or names to limit the - returned information; use `_local` to return information from the - node you're connecting to, leave empty to get information from all - nodes + :arg group_by: Group tasks by nodes or parent/child + relationships Valid choices: nodes, parents, none Default: nodes + :arg nodes: A comma-separated list of node IDs or names to limit + the returned information; use `_local` to return information from the + node you're connecting to, leave empty to get information from all nodes :arg parent_task_id: Return tasks with specified parent task id (node_id:task_number). Set to -1 to return all. - :arg wait_for_completion: Wait for the matching tasks to complete - (default: false) - :arg timeout: Maximum waiting time for `wait_for_completion` + :arg timeout: Explicit operation timeout + :arg wait_for_completion: Wait for the matching tasks to + complete (default: false) """ return self.transport.perform_request("GET", "/_tasks", params=params) @query_params("actions", "nodes", "parent_task_id") def cancel(self, task_id=None, params=None): """ - - ``_ + Cancels a task, if it can be cancelled through an API. + ``_ :arg task_id: Cancel the task with specified task id (node_id:task_number) :arg actions: A comma-separated list of actions that should be cancelled. Leave empty to cancel all. - :arg nodes: A comma-separated list of node IDs or names to limit the - returned information; use `_local` to return information from the - node you're connecting to, leave empty to get information from all - nodes + :arg nodes: A comma-separated list of node IDs or names to limit + the returned information; use `_local` to return information from the + node you're connecting to, leave empty to get information from all nodes :arg parent_task_id: Cancel tasks with specified parent task id (node_id:task_number). Set to -1 to cancel all. """ @@ -53,17 +52,21 @@ class TasksClient(NamespacedClient): "POST", _make_path("_tasks", task_id, "_cancel"), params=params ) - @query_params("wait_for_completion", "timeout") - def get(self, task_id=None, params=None): + @query_params("timeout", "wait_for_completion") + def get(self, task_id, params=None): """ - Retrieve information for a particular task. - ``_ + Returns information about a task. + ``_ - :arg task_id: Return the task with specified id (node_id:task_number) - :arg wait_for_completion: Wait for the matching tasks to complete - (default: false) - :arg timeout: Maximum waiting time for `wait_for_completion` + :arg task_id: Return the task with specified id + (node_id:task_number) + :arg timeout: Explicit operation timeout + :arg wait_for_completion: Wait for the matching tasks to + complete (default: false) """ + if task_id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'task_id'.") + return self.transport.perform_request( "GET", _make_path("_tasks", task_id), params=params ) diff --git a/elasticsearch/client/transform.py b/elasticsearch/client/transform.py new file mode 100644 index 00000000..b4345713 --- /dev/null +++ b/elasticsearch/client/transform.py @@ -0,0 +1,166 @@ +from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH + + +class TransformClient(NamespacedClient): + @query_params("force") + def delete_transform(self, transform_id, params=None): + """ + ``_ + + :arg transform_id: The id of the transform to delete + :arg force: When `true`, the transform is deleted regardless of + its current state. The default value is `false`, meaning that the + transform must be `stopped` before it can be deleted. + """ + if transform_id in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'transform_id'." + ) + + return self.transport.perform_request( + "DELETE", _make_path("_transform", transform_id), params=params + ) + + @query_params("allow_no_match", "from_", "size") + def get_transform(self, transform_id=None, params=None): + """ + ``_ + + :arg transform_id: The id or comma delimited list of id + expressions of the transforms to get, '_all' or '*' implies get all + transforms + :arg allow_no_match: Whether to ignore if a wildcard expression + matches no transforms. (This includes `_all` string or when no + transforms have been specified) + :arg from_: skips a number of transform configs, defaults to 0 + :arg size: specifies a max number of transforms to get, defaults + to 100 + """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + + return self.transport.perform_request( + "GET", _make_path("_transform", transform_id), params=params + ) + + @query_params("allow_no_match", "from_", "size") + def get_transform_stats(self, transform_id, params=None): + """ + ``_ + + :arg transform_id: The id of the transform for which to get + stats. '_all' or '*' implies all transforms + :arg allow_no_match: Whether to ignore if a wildcard expression + matches no transforms. (This includes `_all` string or when no + transforms have been specified) + :arg from_: skips a number of transform stats, defaults to 0 + :arg size: specifies a max number of transform stats to get, + defaults to 100 + """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + + if transform_id in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'transform_id'." + ) + + return self.transport.perform_request( + "GET", _make_path("_transform", transform_id, "_stats"), params=params + ) + + @query_params() + def preview_transform(self, body, params=None): + """ + ``_ + + :arg body: The definition for the transform to preview + """ + if body in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'body'.") + + return self.transport.perform_request( + "POST", "/_transform/_preview", params=params, body=body + ) + + @query_params("defer_validation") + def put_transform(self, transform_id, body, params=None): + """ + ``_ + + :arg transform_id: The id of the new transform. + :arg body: The transform definition + :arg defer_validation: If validations should be deferred until + transform starts, defaults to false. + """ + for param in (transform_id, body): + if param in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument.") + + return self.transport.perform_request( + "PUT", _make_path("_transform", transform_id), params=params, body=body + ) + + @query_params("timeout") + def start_transform(self, transform_id, params=None): + """ + ``_ + + :arg transform_id: The id of the transform to start + :arg timeout: Controls the time to wait for the transform to + start + """ + if transform_id in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'transform_id'." + ) + + return self.transport.perform_request( + "POST", _make_path("_transform", transform_id, "_start"), params=params + ) + + @query_params("allow_no_match", "timeout", "wait_for_completion") + def stop_transform(self, transform_id, params=None): + """ + ``_ + + :arg transform_id: The id of the transform to stop + :arg allow_no_match: Whether to ignore if a wildcard expression + matches no transforms. (This includes `_all` string or when no + transforms have been specified) + :arg timeout: Controls the time to wait until the transform has + stopped. Default to 30 seconds + :arg wait_for_completion: Whether to wait for the transform to + fully stop before returning or not. Default to false + """ + if transform_id in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'transform_id'." + ) + + return self.transport.perform_request( + "POST", _make_path("_transform", transform_id, "_stop"), params=params + ) + + @query_params("defer_validation") + def update_transform(self, transform_id, body, params=None): + """ + ``_ + + :arg transform_id: The id of the transform. + :arg body: The update transform definition + :arg defer_validation: If validations should be deferred until + transform starts, defaults to false. + """ + for param in (transform_id, body): + if param in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument.") + + return self.transport.perform_request( + "POST", + _make_path("_transform", transform_id, "_update"), + params=params, + body=body, + ) diff --git a/elasticsearch/client/watcher.py b/elasticsearch/client/watcher.py index df77f164..71ba772c 100644 --- a/elasticsearch/client/watcher.py +++ b/elasticsearch/client/watcher.py @@ -8,10 +8,12 @@ class WatcherClient(NamespacedClient): ``_ :arg watch_id: Watch ID - :arg action_id: A comma-separated list of the action ids to be acked + :arg action_id: A comma-separated list of the action ids to be + acked """ if watch_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'watch_id'.") + return self.transport.perform_request( "PUT", _make_path("_watcher", "watch", watch_id, "_ack", action_id), @@ -27,6 +29,7 @@ class WatcherClient(NamespacedClient): """ if watch_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'watch_id'.") + return self.transport.perform_request( "PUT", _make_path("_watcher", "watch", watch_id, "_activate"), params=params ) @@ -40,6 +43,7 @@ class WatcherClient(NamespacedClient): """ if watch_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'watch_id'.") + return self.transport.perform_request( "PUT", _make_path("_watcher", "watch", watch_id, "_deactivate"), @@ -55,18 +59,20 @@ class WatcherClient(NamespacedClient): """ if id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'id'.") + return self.transport.perform_request( "DELETE", _make_path("_watcher", "watch", id), params=params ) @query_params("debug") - def execute_watch(self, id=None, body=None, params=None): + def execute_watch(self, body=None, id=None, params=None): """ ``_ - :arg id: Watch ID :arg body: Execution control - :arg debug: indicates whether the watch should execute in debug mode + :arg id: Watch ID + :arg debug: indicates whether the watch should execute in debug + mode """ return self.transport.perform_request( "PUT", @@ -84,6 +90,7 @@ class WatcherClient(NamespacedClient): """ if id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'id'.") + return self.transport.perform_request( "GET", _make_path("_watcher", "watch", id), params=params ) @@ -96,14 +103,15 @@ class WatcherClient(NamespacedClient): :arg id: Watch ID :arg body: The watch :arg active: Specify whether the watch is in/active by default - :arg if_primary_term: only update the watch if the last operation that - has changed the watch has the specified primary term - :arg if_seq_no: only update the watch if the last operation that has - changed the watch has the specified sequence number + :arg if_primary_term: only update the watch if the last + operation that has changed the watch has the specified primary term + :arg if_seq_no: only update the watch if the last operation that + has changed the watch has the specified sequence number :arg version: Explicit version number for concurrency control """ if id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'id'.") + return self.transport.perform_request( "PUT", _make_path("_watcher", "watch", id), params=params, body=body ) @@ -112,17 +120,23 @@ class WatcherClient(NamespacedClient): def start(self, params=None): """ ``_ + """ return self.transport.perform_request("POST", "/_watcher/_start", params=params) - @query_params("emit_stacktraces") + @query_params("emit_stacktraces", "metric") def stats(self, metric=None, params=None): """ ``_ - :arg metric: Controls what additional stat metrics should be include in - the response - :arg emit_stacktraces: Emits stack traces of currently running watches + :arg metric: Controls what additional stat metrics should be + include in the response Valid choices: _all, queued_watches, + current_watches, pending_watches + :arg emit_stacktraces: Emits stack traces of currently running + watches + :arg metric: Controls what additional stat metrics should be + include in the response Valid choices: _all, queued_watches, + current_watches, pending_watches """ return self.transport.perform_request( "GET", _make_path("_watcher", "stats", metric), params=params @@ -132,5 +146,6 @@ class WatcherClient(NamespacedClient): def stop(self, params=None): """ ``_ + """ return self.transport.perform_request("POST", "/_watcher/_stop", params=params) diff --git a/elasticsearch/client/xpack.py b/elasticsearch/client/xpack.py index 7de877c9..78d0249f 100644 --- a/elasticsearch/client/xpack.py +++ b/elasticsearch/client/xpack.py @@ -6,23 +6,24 @@ class XPackClient(NamespacedClient): return getattr(self.client, attr_name) # AUTO-GENERATED-API-DEFINITIONS # - @query_params("categories", "human") + @query_params("categories") def info(self, params=None): """ - Retrieve information about xpack, including build number/timestamp and license status + Retrieve information about xpack, including build number/timestamp and license + status ``_ - :arg categories: Comma-separated list of info categories. Can be any of: - build, license, features - :arg human: Presents additional info for humans (feature descriptions - and X-Pack tagline) + :arg categories: Comma-separated list of info categories. Can be + any of: build, license, features """ return self.transport.perform_request("GET", "/_xpack", params=params) @query_params("master_timeout") def usage(self, params=None): """ - Retrieve information about xpack features usage + Retrieve information about xpack features usage :arg master_timeout: + Specify timeout for watch write operation + ``_ :arg master_timeout: Specify timeout for watch write operation """