From aafbe2c54dbabfaded123e320956e7855e218176 Mon Sep 17 00:00:00 2001 From: Nick Lang Date: Fri, 10 May 2019 12:09:45 -0600 Subject: [PATCH 1/8] Update cat.py to have correct query params --- elasticsearch/client/cat.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/elasticsearch/client/cat.py b/elasticsearch/client/cat.py index f20d8af40..46ac8e8b3 100644 --- a/elasticsearch/client/cat.py +++ b/elasticsearch/client/cat.py @@ -24,9 +24,7 @@ def aliases(self, name=None, params=None): "GET", _make_path("_cat", "aliases", name), params=params ) - @query_params( - "bytes", "size", "format", "h", "help", "local", "master_timeout", "s", "v" - ) + @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 @@ -52,7 +50,7 @@ def allocation(self, node_id=None, params=None): "GET", _make_path("_cat", "allocation", node_id), params=params ) - @query_params("size", "format", "h", "help", "local", "master_timeout", "s", "v") + @query_params("format", "h", "help", "local", "master_timeout", "s", "v") def count(self, index=None, params=None): """ Count provides quick access to the document count of the entire cluster, @@ -111,7 +109,6 @@ def help(self, params=None): @query_params( "bytes", - "time", "size", "format", "h", @@ -218,16 +215,7 @@ def recovery(self, index=None, params=None): ) @query_params( - "bytes", - "time", - "size", - "format", - "h", - "help", - "local", - "master_timeout", - "s", - "v", + "bytes", "size", "format", "h", "help", "local", "master_timeout", "s", "v" ) def shards(self, index=None, params=None): """ @@ -442,6 +430,7 @@ def snapshots(self, repository, params=None): "h", "help", "nodes", + "node_id", "parent_task_id", "s", "v", @@ -458,6 +447,10 @@ def tasks(self, params=None): :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 nodes From c008231f17793cd181a1cc5f38742063dfec06cd Mon Sep 17 00:00:00 2001 From: Nick Lang Date: Fri, 10 May 2019 12:14:15 -0600 Subject: [PATCH 2/8] Add missing api remote_info and missing params * a couple apis have had added query params --- elasticsearch/client/cluster.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/elasticsearch/client/cluster.py b/elasticsearch/client/cluster.py index be694e3e8..63f662faf 100644 --- a/elasticsearch/client/cluster.py +++ b/elasticsearch/client/cluster.py @@ -3,16 +3,17 @@ class ClusterClient(NamespacedClient): @query_params( + "expand_wildcards", "level", "local", "master_timeout", "timeout", "wait_for_active_shards", "wait_for_events", + "wait_for_no_initializing_shards", "wait_for_no_relocating_shards", "wait_for_nodes", "wait_for_status", - "wait_for_no_initializing_shards", ) def health(self, index=None, params=None): """ @@ -20,6 +21,9 @@ def health(self, index=None, params=None): ``_ :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 @@ -66,6 +70,8 @@ def pending_tasks(self, params=None): "ignore_unavailable", "local", "master_timeout", + "wait_for_metadata_version", + "wait_for_timeout", ) def state(self, metric=None, index=None, params=None): """ @@ -87,6 +93,10 @@ def state(self, metric=None, index=None, params=None): :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_timeout: The maximum time to wait for + wait_for_metadata_version before timing out """ if index and not metric: metric = "_all" @@ -174,6 +184,13 @@ def put_settings(self, body=None, params=None): "PUT", "/_cluster/settings", params=params, body=body ) + @query_params() + def remote_info(self, params=None): + """ + ``_ + """ + 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): """ From bfb81d147e408521e7c027d8d0fbaae04c73360d Mon Sep 17 00:00:00 2001 From: Nick Lang Date: Fri, 10 May 2019 12:32:58 -0600 Subject: [PATCH 3/8] Add Split api and add missing query params --- elasticsearch/client/indices.py | 91 ++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 14 deletions(-) diff --git a/elasticsearch/client/indices.py b/elasticsearch/client/indices.py index d371dde4d..dc3b3603a 100644 --- a/elasticsearch/client/indices.py +++ b/elasticsearch/client/indices.py @@ -80,7 +80,7 @@ def flush(self, index=None, params=None): @query_params( "master_timeout", - "request_timeout", + "timeout" "request_timeout", "wait_for_active_shards", "include_type_name", ) @@ -92,6 +92,7 @@ def create(self, index, body=None, params=None): :arg index: The name of the index :arg body: The configuration for the index (`settings` and `mappings`) :arg master_timeout: Specify timeout for connection to master + :arg timeout: Explicit operation timeout :arg request_timeout: Explicit operation timeout :arg wait_for_active_shards: Set the number of active shards to wait for before the operation returns. @@ -112,6 +113,7 @@ def create(self, index, body=None, params=None): "include_defaults", "local", "include_type_name", + "master_timeout", ) def get(self, index, feature=None, params=None): """ @@ -132,6 +134,7 @@ def get(self, index, feature=None, params=None): master node (default: false) :arg include_type_name: Specify whether requests and responses should include a type name (default: depends on Elasticsearch version). + :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'.") @@ -144,7 +147,9 @@ def get(self, index, feature=None, params=None): "expand_wildcards", "ignore_unavailable", "master_timeout", + "timeout", "request_timeout", + "wait_for_active_shards", ) def open(self, index, params=None): """ @@ -161,7 +166,10 @@ def open(self, index, params=None): :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 request_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'.") @@ -175,6 +183,7 @@ def open(self, index, params=None): "ignore_unavailable", "master_timeout", "request_timeout", + "wait_for_active_shards", ) def close(self, index, params=None): """ @@ -193,6 +202,8 @@ def close(self, index, params=None): ignored when unavailable (missing or closed) :arg master_timeout: Specify timeout for connection to master :arg request_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'.") @@ -204,6 +215,7 @@ def close(self, index, params=None): "allow_no_indices", "expand_wildcards", "ignore_unavailable", + "timeout", "master_timeout", "request_timeout", ) @@ -221,6 +233,7 @@ def delete(self, index, params=None): choices are: 'open', 'closed', 'none', 'all' :arg ignore_unavailable: Ignore unavailable indexes (default: false) :arg master_timeout: Specify timeout for connection to master + :arg timeout: Explicit operation timeout :arg request_timeout: Explicit operation timeout """ if index in SKIP_IN_PATH: @@ -291,6 +304,7 @@ def exists_type(self, index, doc_type, params=None): "expand_wildcards", "ignore_unavailable", "master_timeout", + "timeout", "request_timeout", "include_type_name", ) @@ -313,7 +327,8 @@ def put_mapping(self, body, doc_type=None, index=None, params=None): :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 request_timeout: Explicit operation timeout + :arg timeout: Explicit operation timeout + :arg request_timeout: Explicit operation timeout (For pre 7.x ES Clusters) :arg include_type_name: Specify whether requests and responses should include a type name (default: depends on Elasticsearch version). """ @@ -330,6 +345,7 @@ def put_mapping(self, body, doc_type=None, index=None, params=None): "ignore_unavailable", "local", "include_type_name", + "master_timeout", ) def get_mapping(self, index=None, doc_type=None, params=None): """ @@ -350,6 +366,7 @@ def get_mapping(self, index=None, doc_type=None, params=None): master node (default: false) :arg include_type_name: Specify whether requests and responses should include a type name (default: depends on Elasticsearch version). + :arg master_timeout: Specify timeout for connection to master """ return self.transport.perform_request( "GET", _make_path(index, "_mapping", doc_type), params=params @@ -461,7 +478,7 @@ def get_alias(self, index=None, name=None, params=None): "GET", _make_path(index, "_alias", name), params=params ) - @query_params("master_timeout", "request_timeout") + @query_params("master_timeout", "request_timeout", "timeout") def update_aliases(self, body, params=None): """ Update specified aliases. @@ -469,7 +486,8 @@ def update_aliases(self, body, params=None): :arg body: The definition of `actions` to perform :arg master_timeout: Specify timeout for connection to master - :arg request_timeout: Request timeout + :arg request_timeout: Request timeout (For pre 7.x ES Clusters) + :arg timeout: Request timeout """ if body in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'body'.") @@ -477,7 +495,7 @@ def update_aliases(self, body, params=None): "POST", "/_aliases", params=params, body=body ) - @query_params("master_timeout", "request_timeout") + @query_params("master_timeout", "request_timeout", "timeout") def delete_alias(self, index, name, params=None): """ Delete specific alias. @@ -489,7 +507,8 @@ def delete_alias(self, index, name, params=None): wildcards); use `_all` to delete all aliases for the specified indices. :arg master_timeout: Specify timeout for connection to master - :arg request_timeout: Explicit timeout for the operation + :arg request_timeout: Explicit timeout for the operation (for pre 7.x ES clusters) + :arg timeout: Explicit timeout for the operation """ for param in (index, name): if param in SKIP_IN_PATH: @@ -504,6 +523,7 @@ def delete_alias(self, index, name, params=None): "master_timeout", "order", "request_timeout", + "timeout", "include_type_name", ) def put_template(self, name, body, params=None): @@ -520,7 +540,8 @@ def put_template(self, name, body, params=None): :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 request_timeout: Explicit operation timeout + :arg request_timeout: Explicit operation timeout (For pre ES 6 clusters) + :arg timeout: Explicit operation timeout :arg include_type_name: Specify whether requests and responses should include a type name (default: depends on Elasticsearch version). """ @@ -569,7 +590,7 @@ def get_template(self, name=None, params=None): "GET", _make_path("_template", name), params=params ) - @query_params("master_timeout", "request_timeout") + @query_params("master_timeout", "request_timeout", "timeout") def delete_template(self, name, params=None): """ Delete an index template by its name. @@ -577,7 +598,8 @@ def delete_template(self, name, params=None): :arg name: The name of the template :arg master_timeout: Specify timeout for connection to master - :arg request_timeout: Explicit operation timeout + :arg request_timeout: Explicit operation timeout (for pre 7.x clusters) + :arg timeout: Explicit operation timeout """ if name in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'name'.") @@ -592,6 +614,7 @@ def delete_template(self, name, params=None): "ignore_unavailable", "include_defaults", "local", + "master_timeout", ) def get_settings(self, index=None, name=None, params=None): """ @@ -614,6 +637,7 @@ def get_settings(self, index=None, name=None, params=None): the indices., 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( "GET", _make_path(index, "_settings", name), params=params @@ -625,6 +649,7 @@ def get_settings(self, index=None, name=None, params=None): "flat_settings", "ignore_unavailable", "master_timeout", + "timeout", "preserve_existing", ) def put_settings(self, body, index=None, params=None): @@ -648,6 +673,7 @@ def put_settings(self, body, index=None, params=None): :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'.") @@ -657,10 +683,13 @@ def put_settings(self, body, index=None, params=None): @query_params( "completion_fields", + "expand_wildcards", "fielddata_fields", "fields", + "forbid_closed_indices", "groups", "include_segment_file_sizes", + "include_unloaded_segments", "level", "types", ) @@ -674,15 +703,24 @@ def stats(self, index=None, metric=None, params=None): :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` @@ -980,14 +1018,15 @@ def forcemerge(self, index=None, params=None): :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 - :arg operation_threading: TODO: ? + expunge deleted documents (for pre 7.x ES clusters) """ return self.transport.perform_request( "POST", _make_path(index, "_forcemerge"), params=params ) - @query_params("master_timeout", "request_timeout", "wait_for_active_shards") + @query_params( + "master_timeout", "timeout", "request_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 @@ -1006,7 +1045,8 @@ def shrink(self, index, target, body=None, params=None): :arg body: The configuration for the target index (`settings` and `aliases`) :arg master_timeout: Specify timeout for connection to master - :arg request_timeout: Explicit operation timeout + :arg request_timeout: Explicit operation timeout (For pre 7.x ES clusters) + :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. """ @@ -1017,10 +1057,32 @@ def shrink(self, index, target, body=None, params=None): "PUT", _make_path(index, "_shrink", target), params=params, body=body ) + @query_params("master_timeout", "timeout", "wait_for_active_shards") + def split(self, index, target, body=None, params=None): + """ + ``_ + + :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 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. + """ + 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", "master_timeout", "request_timeout", + "timeout", "wait_for_active_shards", "include_type_name", ) @@ -1042,7 +1104,8 @@ def rollover(self, alias, new_index=None, body=None, params=None): but not actually performed even if a condition matches. The default is false :arg master_timeout: Specify timeout for connection to master - :arg request_timeout: Explicit operation timeout + :arg request_timeout: Explicit operation timeout (for pre 7.x ES clusters) + :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 From fc3a7c2e94fe49bea14fc12d3659d2193bdbd8e1 Mon Sep 17 00:00:00 2001 From: Nick Lang Date: Fri, 10 May 2019 12:34:19 -0600 Subject: [PATCH 4/8] Adding processor_grok api --- elasticsearch/client/ingest.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/elasticsearch/client/ingest.py b/elasticsearch/client/ingest.py index c3144e6ed..bc66c331e 100644 --- a/elasticsearch/client/ingest.py +++ b/elasticsearch/client/ingest.py @@ -67,3 +67,12 @@ def simulate(self, body, id=None, params=None): params=params, body=body, ) + + @query_params() + def processor_grok(self, params=None): + """ + ``_ + """ + return self.transport.perform_request( + "GET", "/_ingest/processor/grok", params=params + ) From b22d803f838ec5fbdd071802bc344dfdedee021a Mon Sep 17 00:00:00 2001 From: Nick Lang Date: Fri, 10 May 2019 14:02:14 -0600 Subject: [PATCH 5/8] Adding missing apis: * update by query rethrottle * scripts painless execute * scripts painless context * rank eval * delete by query rethrottle --- elasticsearch/client/__init__.py | 151 +++++++++++++++++++++++++++++-- 1 file changed, 141 insertions(+), 10 deletions(-) diff --git a/elasticsearch/client/__init__.py b/elasticsearch/client/__init__.py index 55f10bc43..ba2f70e27 100644 --- a/elasticsearch/client/__init__.py +++ b/elasticsearch/client/__init__.py @@ -321,7 +321,7 @@ def create(self, index, id, body, doc_type="_doc", params=None): "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. ``_ @@ -329,6 +329,11 @@ def index(self, index, body, doc_type="_doc", id=None, params=None): :arg index: The name of the index :arg body: 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 + 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' @@ -519,7 +524,7 @@ def get(self, index, id, doc_type="_doc", params=None): "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. ``_ @@ -672,6 +677,7 @@ def update(self, index, id, doc_type="_doc", body=None, params=None): "analyze_wildcard", "analyzer", "batched_reduce_size", + "ccs_minimize_roundtrips", "default_operator", "df", "docvalue_fields", @@ -736,6 +742,9 @@ def search(self, index=None, body=None, params=None): 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 @@ -935,10 +944,28 @@ def update_by_query(self, index, body=None, params=None): "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", @@ -956,6 +983,8 @@ def reindex(self, body, params=None): :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 @@ -1104,6 +1133,23 @@ def delete_by_query(self, index, body, params=None): "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, + ) + @query_params( "allow_no_indices", "expand_wildcards", @@ -1142,12 +1188,14 @@ def search_shards(self, index=None, params=None): @query_params( "allow_no_indices", + "ccs_minimize_roundtrips", "expand_wildcards", "explain", "ignore_unavailable", "preference", "profile", "routing", + "rest_total_hits_as_int", "scroll", "search_type", "typed_keys", @@ -1165,6 +1213,9 @@ def search_template(self, index=None, body=None, params=None): :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' @@ -1176,6 +1227,9 @@ def search_template(self, index=None, body=None, params=None): performed on (default: random) :arg profile: Specify whether to profile the query execution :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: @@ -1244,7 +1298,7 @@ def explain(self, index, id, doc_type="_doc", body=None, params=None): "GET", _make_path(index, doc_type, id, "_explain"), params=params, body=body ) - @query_params("scroll", "rest_total_hits_as_int") + @query_params("scroll", "rest_total_hits_as_int", "scroll_id") def scroll(self, scroll_id=None, body=None, params=None): """ Scroll a search request created by specifying the scroll parameter. @@ -1309,6 +1363,11 @@ def delete(self, index, id, doc_type="_doc", params=None): :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 @@ -1341,6 +1400,7 @@ def delete(self, index, id, doc_type="_doc", params=None): "df", "expand_wildcards", "ignore_unavailable", + "ignore_throttled", "lenient", "min_score", "preference", @@ -1372,6 +1432,8 @@ def count(self, doc_type=None, index=None, body=None, params=None): 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 @@ -1446,6 +1508,7 @@ def bulk(self, body, doc_type=None, index=None, params=None): ) @query_params( + "ccs_minimize_roundtrips", "max_concurrent_searches", "max_concurrent_shard_requests", "pre_filter_shard_size", @@ -1462,6 +1525,9 @@ def msearch(self, body, index=None, params=None): 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 @@ -1614,7 +1680,7 @@ def mtermvectors(self, doc_type=None, index=None, body=None, params=None): body=body, ) - @query_params() + @query_params("master_timeout", "timeout") def put_script(self, id, body, context=None, params=None): """ Create a script in given language with specified ID. @@ -1622,7 +1688,9 @@ def put_script(self, id, body, context=None, params=None): :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.") @@ -1630,13 +1698,38 @@ def put_script(self, id, body, context=None, params=None): "PUT", _make_path("_scripts", id, context), params=params, body=body ) - @query_params() + @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'.") @@ -1644,14 +1737,15 @@ def get_script(self, id, params=None): "GET", _make_path("_scripts", id), params=params ) - @query_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( @@ -1670,7 +1764,35 @@ def render_search_template(self, id=None, body=None, params=None): "GET", _make_path("_render", "template", id), params=params, body=body ) - @query_params("max_concurrent_searches", "search_type", "typed_keys") + @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 @@ -1682,6 +1804,9 @@ def msearch_template(self, body, index=None, params=None): 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: @@ -1701,7 +1826,11 @@ def msearch_template(self, body, index=None, params=None): ) @query_params( - "allow_no_indices", "expand_wildcards", "fields", "ignore_unavailable" + "allow_no_indices", + "expand_wildcards", + "fields", + "ignore_unavailable", + "include_unmapped", ) def field_caps(self, index=None, body=None, params=None): """ @@ -1721,6 +1850,8 @@ def field_caps(self, index=None, body=None, params=None): :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 From 62d9c6182e506d7c238b6da499f8270213c8f519 Mon Sep 17 00:00:00 2001 From: Nick Lang Date: Fri, 10 May 2019 14:05:16 -0600 Subject: [PATCH 6/8] add missing query params --- elasticsearch/client/nodes.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/elasticsearch/client/nodes.py b/elasticsearch/client/nodes.py index e009fa898..9549f0620 100644 --- a/elasticsearch/client/nodes.py +++ b/elasticsearch/client/nodes.py @@ -2,12 +2,16 @@ class NodesClient(NamespacedClient): - @query_params() - def reload_secure_settings(self, params=None): + @query_params("timeout") + def reload_secure_settings(self, node_id=None, params=None): """ Reload any settings that have been marked as "reloadable" ``_ + :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. + :arg timeout: Explicit operation timeout """ return self.transport.perform_request( "POST", _make_path("_nodes", "reload_secure_settings"), params=params @@ -82,7 +86,7 @@ def stats(self, node_id=None, metric=None, index_metric=None, params=None): ) @query_params( - "type", "ignore_idle_threads", "interval", "snapshots", "threads", "timeout" + "doc_type", "ignore_idle_threads", "interval", "snapshots", "threads", "timeout" ) def hot_threads(self, node_id=None, params=None): """ From 9cf90b508237c5c8c04e239f0f534cc5eb456f0a Mon Sep 17 00:00:00 2001 From: Nick Lang Date: Fri, 10 May 2019 14:42:09 -0600 Subject: [PATCH 7/8] Add missing xpack apis --- elasticsearch/client/xpack/__init__.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/elasticsearch/client/xpack/__init__.py b/elasticsearch/client/xpack/__init__.py index 8c108c082..21e45a264 100644 --- a/elasticsearch/client/xpack/__init__.py +++ b/elasticsearch/client/xpack/__init__.py @@ -1,13 +1,20 @@ from ..utils import NamespacedClient, query_params +from .ccr import CcrClient +from .data_frame import Data_FrameClient +from .deprecation import DeprecationClient from .graph import GraphClient +from .ilm import IlmClient +from .indices import IndicesClient from .license import LicenseClient +from .migration import MigrationClient +from .ml import MlClient from .monitoring import MonitoringClient +from .rollup import RollupClient from .security import SecurityClient +from .sql import SqlClient +from .ssl import SslClient from .watcher import WatcherClient -from .ml import MlClient -from .migration import MigrationClient -from .deprecation import DeprecationClient class XPackClient(NamespacedClient): @@ -15,14 +22,21 @@ class XPackClient(NamespacedClient): def __init__(self, *args, **kwargs): super(XPackClient, self).__init__(*args, **kwargs) + self.ccr = CcrClient(self.client) + self.data_frame = Data_FrameClient(self.client) + self.deprecation = DeprecationClient(self.client) self.graph = GraphClient(self.client) + self.ilm = IlmClient(self.client) + self.indices = IndicesClient(self.client) self.license = LicenseClient(self.client) + self.migration = MigrationClient(self.client) + self.ml = MlClient(self.client) self.monitoring = MonitoringClient(self.client) + self.rollup = RollupClient(self.client) self.security = SecurityClient(self.client) + self.sql = SqlClient(self.client) + self.ssl = SslClient(self.client) self.watcher = WatcherClient(self.client) - self.ml = MlClient(self.client) - self.migration = MigrationClient(self.client) - self.deprecation = DeprecationClient(self.client) @query_params("categories", "human") def info(self, params=None): From f49a31e2dab391f349a33f4b8496049af14a512b Mon Sep 17 00:00:00 2001 From: Nick Lang Date: Fri, 10 May 2019 16:25:44 -0600 Subject: [PATCH 8/8] Update helpers to account for 7.x scroll api --- elasticsearch/client/__init__.py | 17 ++++------------- elasticsearch/helpers/actions.py | 9 ++------- test_elasticsearch/test_client/__init__.py | 2 +- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/elasticsearch/client/__init__.py b/elasticsearch/client/__init__.py index ba2f70e27..d6e4ba480 100644 --- a/elasticsearch/client/__init__.py +++ b/elasticsearch/client/__init__.py @@ -321,7 +321,7 @@ def create(self, index, id, body, doc_type="_doc", params=None): "version_type", "wait_for_active_shards", ) - def index(self, index, body, doc_type=None, id=None, params=None): + def index(self, index, body, doc_type="_doc", id=None, params=None): """ Adds or updates a typed JSON document in a specific index, making it searchable. ``_ @@ -361,10 +361,7 @@ def index(self, index, body, doc_type=None, id=None, params=None): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") return self.transport.perform_request( - "POST" if id in SKIP_IN_PATH else "PUT", - _make_path(index, doc_type, id), - params=params, - body=body, + "POST", _make_path(index, doc_type, id), params=params, body=body ) @query_params( @@ -524,7 +521,7 @@ def get(self, index, id, doc_type="_doc", params=None): "version", "version_type", ) - def get_source(self, index, id, doc_type=None, params=None): + def get_source(self, index, id, doc_type="_doc", params=None): """ Get the source of a document by it's index, type and id. ``_ @@ -1299,7 +1296,7 @@ def explain(self, index, id, doc_type="_doc", body=None, params=None): ) @query_params("scroll", "rest_total_hits_as_int", "scroll_id") - def scroll(self, scroll_id=None, body=None, params=None): + def scroll(self, body=None, params=None): """ Scroll a search request created by specifying the scroll parameter. ``_ @@ -1312,12 +1309,6 @@ def scroll(self, scroll_id=None, body=None, params=None): 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 diff --git a/elasticsearch/helpers/actions.py b/elasticsearch/helpers/actions.py index 1d233b464..61469f538 100644 --- a/elasticsearch/helpers/actions.py +++ b/elasticsearch/helpers/actions.py @@ -454,13 +454,8 @@ def scan( "Scroll request has only succeeded on %d shards out of %d." % (resp["_shards"]["successful"], resp["_shards"]["total"]), ) - - resp = client.scroll( - scroll_id, - scroll=scroll, - request_timeout=request_timeout, - **scroll_kwargs - ) + scroll_kwargs.update({"scroll_id": scroll_id, "scroll": scroll}) + resp = client.scroll(**scroll_kwargs) scroll_id = resp.get("_scroll_id") finally: diff --git a/test_elasticsearch/test_client/__init__.py b/test_elasticsearch/test_client/__init__.py index 8e0c67ca3..4cd410a6b 100644 --- a/test_elasticsearch/test_client/__init__.py +++ b/test_elasticsearch/test_client/__init__.py @@ -96,4 +96,4 @@ def test_index_uses_post_if_id_is_empty(self): def test_index_uses_put_if_id_is_not_empty(self): self.client.index(index="my-index", id=0, body={}) - self.assert_url_called("PUT", "/my-index/_doc/0") + self.assert_url_called("POST", "/my-index/_doc/0")