Elasticsearch 5.0 APIs

This commit is contained in:
Honza Král
2016-06-28 16:38:32 +02:00
parent f28b634e17
commit a359c5fba2
4 changed files with 299 additions and 8 deletions
+247 -5
View File
@@ -269,7 +269,11 @@ class Elasticsearch(object):
are: 'index', 'create'
:arg parent: ID of the parent document
:arg pipeline: The pipeline id to preprocess incoming documents with
:arg refresh: Refresh the index after performing the operation
: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 timestamp: Explicit timestamp for the document
@@ -432,7 +436,11 @@ class Elasticsearch(object):
:arg lang: The script language (default: groovy)
:arg parent: ID of the parent document. Is is only used for routing and
when for the upsert request
:arg refresh: Refresh the index after performing the operation
: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
@@ -541,6 +549,230 @@ class Elasticsearch(object):
return self.transport.perform_request('GET', _make_path(index,
doc_type, '_search'), params=params, body=body)
@query_params('_source', '_source_exclude', '_source_include',
'allow_no_indices', 'analyze_wildcard', 'analyzer', 'conflicts',
'consistency', 'default_operator', 'df', 'expand_wildcards', 'explain',
'fielddata_fields', 'fields', 'from_', 'ignore_unavailable', 'lenient',
'lowercase_expanded_terms', 'pipeline', 'preference', 'q', 'refresh',
'request_cache', 'requests_per_second', 'routing', 'scroll',
'scroll_size', 'search_timeout', 'search_type', 'size', 'sort', 'stats',
'suggest_field', 'suggest_mode', 'suggest_size', 'suggest_text',
'terminate_after', 'timeout', 'track_scores', 'version', 'version_type',
'wait_for_completion')
def update_by_query(self, index, doc_type=None, body=None, params=None):
"""
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html>`_
: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 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_exclude: A list of fields to exclude from the returned
_source field
:arg _source_include: 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 reindex hits version conflicts?,
default 'abort', valid choices are: 'abort', 'proceed'
:arg consistency: Explicit write consistency setting for the operation,
valid choices are: 'one', 'quorum', 'all'
: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 explain: Specify whether to return detailed information about score
computation as part of a hit
:arg fielddata_fields: A comma-separated list of fields to return as the
field data representation of a field for each hit
:arg fields: A comma-separated list of fields to return 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 lowercase_expanded_terms: Specify whether query terms should be
lowercased
: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 for this request in sub-requests
per second. 0 means set 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 sort: A comma-separated list of <field>:<direction> pairs
:arg stats: Specific 'tag' of the request for logging and statistical
purposes
: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_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
early.
:arg timeout: Time each individual bulk request should wait for shards
that are unavailable., default '1m'
:arg track_scores: Whether to calculate and return scores even if they
are not used for sorting
: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_completion: Should the request should block until the
reindex is complete., default False
"""
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,
doc_type, '_update_by_query'), params=params, body=body)
@query_params('consistency', 'refresh', 'requests_per_second', 'timeout',
'wait_for_completion')
def reindex(self, body, params=None):
"""
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html>`_
:arg body: The search definition using the Query DSL and the prototype
for the index request.
:arg consistency: Explicit write consistency setting for the operation,
valid choices are: 'one', 'quorum', 'all'
:arg refresh: Should the effected indexes be refreshed?
:arg requests_per_second: The throttle for this request in sub-requests
per second. 0 means set no throttle., default 0
:arg timeout: Time each individual bulk request should wait for shards
that are unavailable., default '1m'
:arg wait_for_completion: Should the request should block until the
reindex is complete., default False
"""
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('_source', '_source_exclude', '_source_include',
'allow_no_indices', 'analyze_wildcard', 'analyzer', 'conflicts',
'consistency', 'default_operator', 'df', 'expand_wildcards', 'explain',
'fielddata_fields', 'fields', 'from_', 'ignore_unavailable', 'lenient',
'lowercase_expanded_terms', 'preference', 'q', 'refresh',
'request_cache', 'requests_per_second', 'routing', 'scroll',
'scroll_size', 'search_timeout', 'search_type', 'size', 'sort', 'stats',
'suggest_field', 'suggest_mode', 'suggest_size', 'suggest_text',
'terminate_after', 'timeout', 'track_scores', 'version',
'wait_for_completion')
def delete_by_query(self, index, body, doc_type=None, params=None):
"""
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html>`_
: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_exclude: A list of fields to exclude from the returned
_source field
:arg _source_include: 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 consistency: Explicit write consistency setting for the operation,
valid choices are: 'one', 'quorum', 'all'
: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 explain: Specify whether to return detailed information about score
computation as part of a hit
:arg fielddata_fields: A comma-separated list of fields to return as the
field data representation of a field for each hit
:arg fields: A comma-separated list of fields to return 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 lowercase_expanded_terms: Specify whether query terms should be
lowercased
: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. 0 means set 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 sort: A comma-separated list of <field>:<direction> pairs
:arg stats: Specific 'tag' of the request for logging and statistical
purposes
: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_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
early.
:arg timeout: Time each individual bulk request should wait for shards
that are unavailable., default '1m'
:arg track_scores: Whether to calculate and return scores even if they
are not used for sorting
:arg version: Specify whether to return document version as part of a
hit
:arg wait_for_completion: Should the request should block until the
delete-by-query is complete., default False
"""
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('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'local', 'preference', 'routing')
def search_shards(self, index=None, doc_type=None, params=None):
@@ -703,7 +935,11 @@ class Elasticsearch(object):
:arg consistency: Specific write consistency setting for the operation,
valid choices are: 'one', 'quorum', 'all'
:arg parent: ID of parent document
:arg refresh: Refresh the index after performing the operation
: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
@@ -780,7 +1016,11 @@ class Elasticsearch(object):
:arg fields: Default comma-separated list of fields to return in the
response for updates
:arg pipeline: The pipeline id to preprocess incoming documents with
:arg refresh: Refresh the index after performing the operation
: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
"""
@@ -789,7 +1029,7 @@ class Elasticsearch(object):
return self.transport.perform_request('POST', _make_path(index,
doc_type, '_bulk'), params=params, body=self._bulk_body(body))
@query_params('search_type')
@query_params('max_concurrent_searches', 'search_type')
def msearch(self, body, index=None, doc_type=None, params=None):
"""
Execute several search requests within the same API.
@@ -800,6 +1040,8 @@ class Elasticsearch(object):
: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 search_type: Search operation type, valid choices are:
'query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch',
'dfs_query_and_fetch'
+4 -1
View File
@@ -94,7 +94,8 @@ class ClusterClient(NamespacedClient):
url = _make_path('_cluster/stats/nodes', node_id)
return self.transport.perform_request('GET', url, params=params)
@query_params('dry_run', 'explain', 'master_timeout', 'metric', 'timeout')
@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.
@@ -110,6 +111,8 @@ class ClusterClient(NamespacedClient):
: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 timeout: Explicit operation timeout
"""
return self.transport.perform_request('POST', '/_cluster/reroute',
+36 -2
View File
@@ -777,7 +777,11 @@ class IndicesClient(NamespacedClient):
'operation_threading', 'status')
def shard_stores(self, index=None, params=None):
"""
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-shard-stores.html>`_
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.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-shards-stores.html>`_
:arg index: A comma-separated list of index names; use `_all` or empty
string to perform the operation on all indices
@@ -802,7 +806,15 @@ class IndicesClient(NamespacedClient):
'operation_threading', 'wait_for_merge')
def forcemerge(self, index=None, params=None):
"""
`<http://www.elastic.co/guide/en/elasticsearch/reference/2.1/indices-forcemerge.html>`_
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.
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.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html>`_
:arg index: A comma-separated list of index names; use `_all` or empty
string to perform the operation on all indices
@@ -854,3 +866,25 @@ class IndicesClient(NamespacedClient):
return self.transport.perform_request('PUT', _make_path(index,
'_shrink', target), params=params, body=body)
@query_params('master_timeout', 'timeout')
def rollover(self, alias, new_index=None, body=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.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html>`_
:arg alias: The name of the alias to rollover
:arg new_index: The name of the rollover index
:arg body: The conditions that needs to be met for executing rollover
:arg master_timeout: Specify timeout for connection to master
:arg timeout: Explicit operation timeout
"""
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)
+12
View File
@@ -47,3 +47,15 @@ class TasksClient(NamespacedClient):
return self.transport.perform_request('POST', _make_path('_tasks',
task_id, '_cancel'), params=params)
@query_params('wait_for_completion')
def get(self, task_id=None, params=None):
"""
Retrieve information for a particular task.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html>`_
: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)
"""
return self.transport.perform_request('GET', _make_path('_tasks',
task_id), params=params)