Updated to new version of elasticsearch spec

This commit is contained in:
Honza Král
2015-04-20 20:13:13 +02:00
parent eee5701dd0
commit 01ff9da23d
5 changed files with 75 additions and 114 deletions
+1
View File
@@ -9,6 +9,7 @@ Changelog
* Add support for ``query_cache`` parameter when searching
* helpers have been made more secure by changing defaults to raise an
exception on errors
* removed deprecated options ``replication`` and the deprecated benchmark api.
1.4.0 (2015-02-11)
------------------
+43 -72
View File
@@ -200,7 +200,7 @@ class Elasticsearch(object):
return data
@query_params('consistency', 'parent', 'percolate', 'refresh',
'replication', 'routing', 'timeout', 'timestamp', 'ttl', 'version', 'version_type')
'routing', 'timeout', 'timestamp', 'ttl', 'version', 'version_type')
def create(self, index, doc_type, body, id=None, params=None):
"""
Adds a typed JSON document in a specific index, making it searchable.
@@ -215,7 +215,6 @@ class Elasticsearch(object):
:arg parent: ID of the parent document
:arg percolate: Percolator queries to execute while indexing the document
:arg refresh: Refresh the index after performing the operation
:arg replication: Specific replication type (default: sync)
:arg routing: Specific routing value
:arg timeout: Explicit operation timeout
:arg timestamp: Explicit timestamp for the document
@@ -226,7 +225,7 @@ class Elasticsearch(object):
return self.index(index, doc_type, body, id=id, params=params, op_type='create')
@query_params('consistency', 'op_type', 'parent', 'refresh',
'replication', 'routing', 'timeout', 'timestamp', 'ttl', 'version', 'version_type')
'routing', 'timeout', 'timestamp', 'ttl', 'version', 'version_type')
def index(self, index, doc_type, body, id=None, params=None):
"""
Adds or updates a typed JSON document in a specific index, making it searchable.
@@ -240,7 +239,6 @@ class Elasticsearch(object):
:arg op_type: Explicit operation type (default: index)
:arg parent: ID of the parent document
:arg refresh: Refresh the index after performing the operation
:arg replication: Specific replication type (default: sync)
:arg routing: Specific routing value
:arg timeout: Explicit operation timeout
:arg timestamp: Explicit timestamp for the document
@@ -388,8 +386,9 @@ class Elasticsearch(object):
return data
@query_params('consistency', 'fields', 'lang', 'parent', 'refresh',
'replication', 'retry_on_conflict', 'routing', 'script', 'timeout',
'timestamp', 'ttl', 'version', 'version_type')
'retry_on_conflict', 'routing', 'script', 'script_id',
'scripted_upsert', 'timeout', 'timestamp', 'ttl', 'version',
'version_type')
def update(self, index, doc_type, id, body=None, params=None):
"""
Update a document based on a script or partial data provided.
@@ -404,11 +403,13 @@ class Elasticsearch(object):
:arg lang: The script language (default: mvel)
:arg parent: ID of the parent document
:arg refresh: Refresh the index after performing the operation
:arg replication: Specific replication type (default: sync)
: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 script: The URL-encoded script definition (instead of using request body)
:arg script_id: The id of a stored script
:arg scripted_upsert: True if the script referenced in script or
script_id should be called to perform inserts - defaults to false
:arg timeout: Explicit operation timeout
:arg timestamp: Explicit timestamp for the document
:arg ttl: Expiration time for the document
@@ -429,7 +430,7 @@ class Elasticsearch(object):
'lowercase_expanded_terms', 'from_', 'preference', 'q', 'query_cache',
'routing', 'scroll', 'search_type', 'size', 'sort', 'source', 'stats',
'suggest_field', 'suggest_mode', 'suggest_size', 'suggest_text',
'timeout', 'version')
'terminate_after', 'timeout', 'track_scores', 'version')
def search(self, index=None, doc_type=None, body=None, params=None):
"""
Execute a search query and get back search hits that match the query.
@@ -485,7 +486,12 @@ class Elasticsearch(object):
:arg suggest_mode: Specify suggest mode (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
early.
:arg timeout: Explicit operation timeout
: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
"""
# from is a reserved word so it cannot be used, use from_ instead
@@ -632,9 +638,8 @@ class Elasticsearch(object):
body=body, params=params)
return data
@query_params('consistency', 'parent', 'refresh', 'replication', 'routing',
'timeout', 'version', 'version_type')
@query_params('consistency', 'parent', 'refresh', 'routing', 'timeout',
'version', 'version_type')
def delete(self, index, doc_type, id, params=None):
"""
Delete a typed JSON document from a specific index based on its id.
@@ -646,7 +651,6 @@ class Elasticsearch(object):
:arg consistency: Specific write consistency setting for the operation
:arg parent: ID of parent document
:arg refresh: Refresh the index after performing the operation
:arg replication: Specific replication type (default: sync)
:arg routing: Specific routing value
:arg timeout: Explicit operation timeout
:arg version: Explicit version number for concurrency control
@@ -659,7 +663,7 @@ class Elasticsearch(object):
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'min_score', 'preference', 'q', 'routing', 'source')
'min_score', 'preference', 'q', 'routing')
def count(self, index=None, doc_type=None, body=None, params=None):
"""
Execute a query and get the number of matches for that query.
@@ -680,7 +684,6 @@ class Elasticsearch(object):
performed on (default: random)
:arg q: Query in the Lucene query string syntax
:arg routing: Specific routing value
:arg source: The URL-encoded query definition (instead of using the request body)
"""
if doc_type and not index:
index = '_all'
@@ -689,7 +692,7 @@ class Elasticsearch(object):
params=params, body=body)
return data
@query_params('consistency', 'refresh', 'routing', 'replication', 'timeout')
@query_params('consistency', 'refresh', 'routing', 'timeout')
def bulk(self, body, index=None, doc_type=None, params=None):
"""
Perform many index/delete operations in a single API call.
@@ -706,7 +709,6 @@ class Elasticsearch(object):
:arg consistency: Explicit write consistency setting for the operation
:arg refresh: Refresh the index after performing the operation
:arg routing: Specific routing value
:arg replication: Explicitly set the replication type (default: sync)
:arg timeout: Explicit operation timeout
"""
if body in SKIP_IN_PATH:
@@ -736,7 +738,7 @@ class Elasticsearch(object):
@query_params('allow_no_indices', 'analyzer', 'consistency',
'default_operator', 'df', 'expand_wildcards', 'ignore_unavailable', 'q',
'replication', 'routing', 'source', 'timeout')
'routing', 'source', 'timeout')
def delete_by_query(self, index, doc_type=None, body=None, params=None):
"""
Delete documents from one or more indices and one or more types based on a query.
@@ -761,7 +763,6 @@ class Elasticsearch(object):
:arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed)
:arg q: Query in the Lucene query string syntax
:arg replication: Specific replication type, default u'sync'
:arg routing: Specific routing value
:arg source: The URL-encoded query definition (instead of using the
request body)
@@ -774,7 +775,7 @@ class Elasticsearch(object):
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'preference', 'routing', 'source')
'preference', 'routing')
def suggest(self, body, index=None, params=None):
"""
The suggest feature suggests similar looking terms based on a provided
@@ -794,7 +795,6 @@ class Elasticsearch(object):
:arg preference: Specify the node or shard the operation should be
performed on (default: random)
:arg routing: Specific routing value
:arg source: The URL-encoded request definition (instead of using request body)
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
@@ -803,8 +803,9 @@ class Elasticsearch(object):
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'percolate_format', 'percolate_index', 'percolate_type', 'preference',
'routing', 'version', 'version_type')
'percolate_format', 'percolate_index', 'percolate_preference',
'percolate_routing', 'percolate_type', 'preference', 'routing',
'version', 'version_type')
def percolate(self, index, doc_type, id=None, body=None, params=None):
"""
The percolator allows to register queries against an index, and then
@@ -830,6 +831,10 @@ class Elasticsearch(object):
objects
:arg percolate_index: The index to percolate the document into. Defaults
to index.
:arg percolate_preference: Which shard to prefer when executing the
percolate request.
:arg percolate_routing: The routing value to use when percolating the
existing document.
:arg percolate_type: The type to percolate document into. Defaults to
type.
:arg preference: Specify the node or shard the operation should be
@@ -965,9 +970,10 @@ class Elasticsearch(object):
params=params, body=body)
return data
@query_params('field_statistics', 'fields', 'offsets', 'parent', 'payloads',
'positions', 'preference', 'realtime', 'routing', 'term_statistics')
def termvectors(self, index, doc_type, id, body=None, params=None):
@query_params('dfs', 'field_statistics', 'fields', 'offsets', 'parent',
'payloads', 'positions', 'preference', 'realtime', 'routing',
'term_statistics', 'version', 'version_type')
def termvectors(self, index, doc_type, id=None, body=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
@@ -978,8 +984,12 @@ class Elasticsearch(object):
:arg index: The index in which the document resides.
:arg doc_type: The type of the document.
:arg id: The id of the document.
:arg body: Define parameters. See documentation.
: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 dfs: Specifies if distributed frequencies should be returned
instead shard frequencies., default False
:arg field_statistics: Specifies if document count, sum of document
frequencies and sum of total term frequencies should be returned.,
default True
@@ -998,6 +1008,8 @@ class Elasticsearch(object):
:arg routing: Specific routing value.
:arg term_statistics: Specifies if total term frequency and document
frequency should be returned., default False
:arg version: Explicit version number for concurrency control
:arg version_type: Specific version type
"""
for param in (index, doc_type, id):
if param in SKIP_IN_PATH:
@@ -1018,7 +1030,8 @@ class Elasticsearch(object):
termvector.__doc__ = termvectors.__doc__
@query_params('field_statistics', 'fields', 'ids', 'offsets', 'parent',
'payloads', 'positions', 'preference', 'routing', 'term_statistics')
'payloads', 'positions', 'preference', 'realtime', 'routing',
'term_statistics')
def mtermvectors(self, index=None, doc_type=None, body=None, params=None):
"""
Multi termvectors API allows to get multiple termvectors based on an
@@ -1053,6 +1066,8 @@ class Elasticsearch(object):
: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
@@ -1064,50 +1079,6 @@ class Elasticsearch(object):
doc_type, '_mtermvectors'), params=params, body=body)
return data
@query_params('verbose')
def benchmark(self, index=None, doc_type=None, body=None, params=None):
"""
The benchmark API provides a standard mechanism for submitting queries
and measuring their performance relative to one another.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/search-benchmark.html>`_
:arg index: A comma-separated list of index names; use `_all` or empty
string to perform the operation on all indices
:arg doc_type: The name of the document type
:arg body: The search definition using the Query DSL
:arg verbose: Specify whether to return verbose statistics about each
iteration (default: false)
"""
_, data = self.transport.perform_request('PUT', _make_path(index,
doc_type, '_bench'), params=params, body=body)
return data
@query_params()
def abort_benchmark(self, name=None, params=None):
"""
Aborts a running benchmark.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/search-benchmark.html>`_
:arg name: A benchmark name
"""
_, data = self.transport.perform_request('POST', _make_path('_bench',
'abort', name), params=params)
return data
@query_params()
def list_benchmarks(self, index=None, doc_type=None, params=None):
"""
View the progress of long-running benchmarks.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/search-benchmark.html>`_
:arg index: A comma-separated list of index names; use `_all` or empty
string to perform the operation on all indices
:arg doc_type: The name of the document type
"""
_, data = self.transport.perform_request('GET', _make_path(index,
doc_type, '_bench'), params=params)
return data
@query_params('op_type', 'version', 'version_type')
def put_script(self, lang, id, body, params=None):
"""
+1
View File
@@ -197,6 +197,7 @@ class CatClient(NamespacedClient):
def segments(self, index=None, params=None):
"""
The segments command is the detailed view of Lucene segments per index.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-segments.html>`_
:arg index: A comma-separated list of index names to limit the returned
information
+23 -40
View File
@@ -53,8 +53,8 @@ class IndicesClient(NamespacedClient):
params=params)
return data
@query_params('force', 'full', 'allow_no_indices', 'expand_wildcards',
'ignore_indices', 'ignore_unavailable')
@query_params('allow_no_indices', 'expand_wildcards', 'force', 'full',
'ignore_indices', 'ignore_unavailable', 'wait_if_ongoing')
def flush(self, index=None, params=None):
"""
Explicitly flush one or more indices.
@@ -75,6 +75,11 @@ class IndicesClient(NamespacedClient):
ignore `missing` ones (default: none)
: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 false and will cause an exception
to be thrown on the shard level if another flush operation is
already running.
"""
_, data = self.transport.perform_request('POST', _make_path(index, '_flush'),
params=params)
@@ -120,8 +125,8 @@ class IndicesClient(NamespacedClient):
feature), params=params)
return data
@query_params('timeout', 'master_timeout' 'allow_no_indices', 'expand_wildcards',
'ignore_unavailable')
@query_params('timeout', 'master_timeout' 'allow_no_indices',
'expand_wildcards', 'ignore_unavailable')
def open(self, index, params=None):
"""
Open a closed index to make it available for search.
@@ -213,8 +218,8 @@ class IndicesClient(NamespacedClient):
return False
return True
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_indices', 'ignore_unavailable',
'local')
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_indices',
'ignore_unavailable', 'local')
def exists_type(self, index, doc_type, params=None):
"""
Check if a type/types exists in an index/indices.
@@ -251,11 +256,11 @@ class IndicesClient(NamespacedClient):
Register specific mapping definition for a specific type.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html>`_
: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 body: The mapping definition
:arg index: A 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)
@@ -275,8 +280,8 @@ class IndicesClient(NamespacedClient):
params=params, body=body)
return data
@query_params('ignore_unavailable', 'allow_no_indices',
'expand_wildcards', 'local')
@query_params('ignore_unavailable', 'allow_no_indices', 'expand_wildcards',
'local')
def get_mapping(self, index=None, doc_type=None, params=None):
"""
Retrieve mapping definition of index or index/type.
@@ -805,8 +810,7 @@ class IndicesClient(NamespacedClient):
return data
@query_params('explain', 'allow_no_indices', 'expand_wildcards',
'ignore_indices', 'ignore_unavailable', 'operation_threading', 'q',
'source')
'ignore_indices', 'ignore_unavailable', 'operation_threading', 'q')
def validate_query(self, index=None, doc_type=None, body=None, params=None):
"""
Validate a potentially expensive query without executing it.
@@ -829,8 +833,6 @@ class IndicesClient(NamespacedClient):
when unavailable (missing or closed)
:arg operation_threading: TODO: ?
:arg q: Query in the Lucene query string syntax
:arg source: The URL-encoded query definition (instead of using the
request body)
"""
_, data = self.transport.perform_request('GET', _make_path(index, doc_type, '_validate', 'query'),
params=params, body=body)
@@ -838,7 +840,7 @@ class IndicesClient(NamespacedClient):
@query_params('field_data', 'fielddata', 'fields', 'filter', 'filter_cache',
'filter_keys', 'id', 'id_cache', 'allow_no_indices', 'expand_wildcards',
'ignore_indices', 'ignore_unavailable', 'recycler')
'ignore_indices', 'ignore_unavailable', 'query_cache', 'recycler')
def clear_cache(self, index=None, params=None):
"""
Clear either all caches or specific cached associated with one ore more indices.
@@ -864,6 +866,7 @@ class IndicesClient(NamespacedClient):
ignore `missing` ones (default: none)
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
:arg query_cache: Clear query cache
:arg recycler: Clear the recycler cache
"""
_, data = self.transport.perform_request('POST', _make_path(index, '_cache', 'clear'),
@@ -892,30 +895,8 @@ class IndicesClient(NamespacedClient):
'_recovery'), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_indices', 'ignore_unavailable')
def snapshot_index(self, index=None, params=None):
"""
Explicitly perform a snapshot through the gateway of one or more indices (backup them).
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-gateway-snapshot.html>`_
: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.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones (default: none)
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
"""
_, data = self.transport.perform_request('POST',
_make_path(index, '_gateway', 'snapshot'), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'wait_for_completion')
'only_ancient_segments', 'wait_for_completion')
def upgrade(self, index=None, params=None):
"""
Upgrade one or more indices to the latest format through an API.
@@ -930,8 +911,10 @@ class IndicesClient(NamespacedClient):
indices that are open, closed or both., default u'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)
the all segments are upgraded (default: true)
"""
_, data = self.transport.perform_request('POST', _make_path(index,
'_upgrade'), params=params)
+7 -2
View File
@@ -41,7 +41,8 @@ class NodesClient(NamespacedClient):
'nodes', node_id, '_shutdown'), params=params)
return data
@query_params('completion_fields', 'fielddata_fields', 'fields', 'groups', 'human', 'level', 'types')
@query_params('completion_fields', 'fielddata_fields', 'fields', 'groups',
'human', 'level', 'types')
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
@@ -80,7 +81,8 @@ class NodesClient(NamespacedClient):
node_id, 'stats', metric, index_metric), params=params)
return data
@query_params('type_', 'interval', 'snapshots', 'threads')
@query_params('type_', 'ignore_idle_threads', 'interval', 'snapshots',
'threads')
def hot_threads(self, node_id=None, params=None):
"""
An API allowing to get the current hot threads on each node in the cluster.
@@ -91,6 +93,9 @@ class NodesClient(NamespacedClient):
node you're connecting to, leave empty to get information from all
nodes
:arg type_: The type to sample (default: cpu)
: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