2.0 compatibility

This commit is contained in:
Honza Král
2015-08-25 01:21:45 +02:00
parent ec5d4ef3ce
commit 36d8d4b545
7 changed files with 683 additions and 575 deletions
+232 -176
View File
@@ -184,10 +184,11 @@ class Elasticsearch(object):
def ping(self, params=None): def ping(self, params=None):
""" """
Returns True if the cluster is up, False otherwise. Returns True if the cluster is up, False otherwise.
`<http://www.elastic.co/guide/>`_
""" """
try: try:
self.transport.perform_request('HEAD', '/', params=params) self.transport.perform_request('HEAD', '/', params=params)
except TransportError: except NotFoundError:
return False return False
return True return True
@@ -195,12 +196,13 @@ class Elasticsearch(object):
def info(self, params=None): def info(self, params=None):
""" """
Get the basic info from the current cluster. Get the basic info from the current cluster.
`<http://www.elastic.co/guide/>`_
""" """
_, data = self.transport.perform_request('GET', '/', params=params) _, data = self.transport.perform_request('GET', '/', params=params)
return data return data
@query_params('consistency', 'parent', 'percolate', 'refresh', @query_params('consistency', 'parent', 'refresh', 'routing',
'routing', 'timeout', 'timestamp', 'ttl', 'version', 'version_type') 'timeout', 'timestamp', 'ttl', 'version', 'version_type')
def create(self, index, doc_type, body, id=None, params=None): def create(self, index, doc_type, body, id=None, params=None):
""" """
Adds a typed JSON document in a specific index, making it searchable. Adds a typed JSON document in a specific index, making it searchable.
@@ -210,22 +212,25 @@ class Elasticsearch(object):
:arg index: The name of the index :arg index: The name of the index
:arg doc_type: The type of the document :arg doc_type: The type of the document
:arg body: The document :arg body: The document
:arg id: Specific document ID (when the POST method is used) :arg id: Document ID
:arg consistency: Explicit write consistency setting for the operation :arg consistency: Explicit write consistency setting for the operation,
valid choices are: 'one', 'quorum', 'all'
:arg op_type: Explicit operation type, default 'index', valid choices
are: 'index', 'create'
:arg parent: ID of the parent document :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 refresh: Refresh the index after performing the operation
:arg routing: Specific routing value :arg routing: Specific routing value
:arg timeout: Explicit operation timeout :arg timeout: Explicit operation timeout
:arg timestamp: Explicit timestamp for the document :arg timestamp: Explicit timestamp for the document
:arg ttl: Expiration time for the document :arg ttl: Expiration time for the document
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Specific version type :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
return self.index(index, doc_type, body, id=id, params=params, op_type='create') return self.index(index, doc_type, body, id=id, params=params, op_type='create')
@query_params('consistency', 'op_type', 'parent', 'refresh', @query_params('consistency', 'op_type', 'parent', 'refresh', 'routing',
'routing', 'timeout', 'timestamp', 'ttl', 'version', 'version_type') 'timeout', 'timestamp', 'ttl', 'version', 'version_type')
def index(self, index, doc_type, body, id=None, params=None): 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. Adds or updates a typed JSON document in a specific index, making it searchable.
@@ -235,8 +240,10 @@ class Elasticsearch(object):
:arg doc_type: The type of the document :arg doc_type: The type of the document
:arg body: The document :arg body: The document
:arg id: Document ID :arg id: Document ID
:arg consistency: Explicit write consistency setting for the operation :arg consistency: Explicit write consistency setting for the operation,
:arg op_type: Explicit operation type (default: index) valid choices are: 'one', 'quorum', 'all'
:arg op_type: Explicit operation type, default 'index', valid choices
are: 'index', 'create'
:arg parent: ID of the parent document :arg parent: ID of the parent document
:arg refresh: Refresh the index after performing the operation :arg refresh: Refresh the index after performing the operation
:arg routing: Specific routing value :arg routing: Specific routing value
@@ -244,26 +251,26 @@ class Elasticsearch(object):
:arg timestamp: Explicit timestamp for the document :arg timestamp: Explicit timestamp for the document
:arg ttl: Expiration time for the document :arg ttl: Expiration time for the document
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Specific version type :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
for param in (index, doc_type, body): for param in (index, doc_type, body):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
method = 'POST' if id in SKIP_IN_PATH else 'PUT' _, data = self.transport.perform_request('POST' if id in SKIP_IN_PATH else 'PUT',
_, data = self.transport.perform_request(method,
_make_path(index, doc_type, id), params=params, body=body) _make_path(index, doc_type, id), params=params, body=body)
return data return data
@query_params('parent', 'preference', 'realtime', 'refresh', 'routing') @query_params('parent', 'preference', 'realtime', 'refresh', 'routing')
def exists(self, index, id, doc_type='_all', params=None): def exists(self, index, doc_type, id, params=None):
""" """
Returns a boolean indicating whether or not given document exists in Elasticsearch. Returns a boolean indicating whether or not given document exists in Elasticsearch.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html>`_
:arg index: The name of the index :arg index: The name of the index
:arg doc_type: The type of the document (use `_all` to fetch the first
document matching the ID across all types)
:arg id: The document ID :arg id: The document ID
:arg doc_type: The type of the document (uses `_all` by default to
fetch the first document matching the ID across all types)
:arg parent: The ID of the parent document :arg parent: The ID of the parent document
:arg preference: Specify the node or shard the operation should be :arg preference: Specify the node or shard the operation should be
performed on (default: random) performed on (default: random)
@@ -277,22 +284,24 @@ class Elasticsearch(object):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
try: try:
self.transport.perform_request('HEAD', _make_path(index, doc_type, id), params=params) self.transport.perform_request('HEAD', _make_path(index, doc_type,
id), params=params)
except NotFoundError: except NotFoundError:
return False return False
return True return True
@query_params('_source', '_source_exclude', '_source_include', 'fields', @query_params('_source', '_source_exclude', '_source_include', 'fields',
'parent', 'preference', 'realtime', 'refresh', 'routing', 'version', 'version_type') 'parent', 'preference', 'realtime', 'refresh', 'routing', 'version',
'version_type')
def get(self, index, id, doc_type='_all', params=None): def get(self, index, id, doc_type='_all', params=None):
""" """
Get a typed JSON document from the index based on its id. Get a typed JSON document from the index based on its id.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html>`_
:arg index: The name of the index :arg index: The name of the index
:arg doc_type: The type of the document (use `_all` to fetch the first
document matching the ID across all types)
:arg id: The document ID :arg id: The document ID
:arg doc_type: The type of the document (uses `_all` by default 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 :arg _source: True or false to return the _source field or not, or a
list of fields to return list of fields to return
:arg _source_exclude: A list of fields to exclude from the returned :arg _source_exclude: A list of fields to exclude from the returned
@@ -309,26 +318,27 @@ class Elasticsearch(object):
performing the operation performing the operation
:arg routing: Specific routing value :arg routing: Specific routing value
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Explicit version number for concurrency control :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
for param in (index, doc_type, id): for param in (index, doc_type, id):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path(index, doc_type, id), _, data = self.transport.perform_request('GET', _make_path(index,
params=params) doc_type, id), params=params)
return data return data
@query_params('_source', '_source_exclude', '_source_include', 'parent', 'preference', @query_params('_source', '_source_exclude', '_source_include', 'parent',
'realtime', 'refresh', 'routing', 'version', 'version_type') 'preference', 'realtime', 'refresh', 'routing', 'version',
def get_source(self, index, id, doc_type='_all', params=None): 'version_type')
def get_source(self, index, doc_type, id, params=None):
""" """
Get the source of a document by it's index, type and id. Get the source of a document by it's index, type and id.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html>`_
:arg index: The name of the index :arg index: The name of the index
:arg doc_type: The type of the document (uses `_all` by default to :arg doc_type: The type of the document; use `_all` to fetch the first
fetch the first document matching the ID across all types) document matching the ID across all types
:arg id: The document ID :arg id: The document ID
:arg _source: True or false to return the _source field or not, or a :arg _source: True or false to return the _source field or not, or a
list of fields to return list of fields to return
@@ -339,29 +349,32 @@ class Elasticsearch(object):
:arg parent: The ID of the parent document :arg parent: The ID of the parent document
:arg preference: Specify the node or shard the operation should be :arg preference: Specify the node or shard the operation should be
performed on (default: random) performed on (default: random)
:arg realtime: Specify whether to perform the operation in realtime or search mode :arg realtime: Specify whether to perform the operation in realtime or
search mode
:arg refresh: Refresh the shard containing the document before :arg refresh: Refresh the shard containing the document before
performing the operation performing the operation
:arg routing: Specific routing value :arg routing: Specific routing value
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Explicit version number for concurrency control :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
for param in (index, doc_type, id): for param in (index, doc_type, id):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path(index, doc_type, id, '_source'), _, data = self.transport.perform_request('GET', _make_path(index,
params=params) doc_type, id, '_source'), params=params)
return data return data
@query_params('_source', '_source_exclude', '_source_include', 'fields', @query_params('_source', '_source_exclude', '_source_include', 'fields',
'parent', 'preference', 'realtime', 'refresh', 'routing') 'preference', 'realtime', 'refresh')
def mget(self, body, index=None, doc_type=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. Get multiple documents based on an index, type (optional) and ids.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html>`_
:arg body: Document identifiers; can be either `docs` (containing full :arg body: Document identifiers; can be either `docs` (containing full
document information) or `ids` (when index and type is provided in the URL. document information) or `ids` (when index and type is provided in
the URL.
:arg index: The name of the index :arg index: The name of the index
:arg doc_type: The type of the document :arg doc_type: The type of the document
:arg _source: True or false to return the _source field or not, or a :arg _source: True or false to return the _source field or not, or a
@@ -371,18 +384,17 @@ class Elasticsearch(object):
:arg _source_include: A list of fields to extract and return from the :arg _source_include: A list of fields to extract and return from the
_source field _source field
:arg fields: A comma-separated list of fields to return in the response :arg fields: A comma-separated list of fields to return in the response
:arg parent: The ID of the parent document
:arg preference: Specify the node or shard the operation should be :arg preference: Specify the node or shard the operation should be
performed on (default: random) performed on (default: random)
:arg realtime: Specify whether to perform the operation in realtime or search mode :arg realtime: Specify whether to perform the operation in realtime or
search mode
:arg refresh: Refresh the shard containing the document before :arg refresh: Refresh the shard containing the document before
performing the operation performing the operation
:arg routing: Specific routing value
""" """
if body in SKIP_IN_PATH: if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.") raise ValueError("Empty value passed for a required argument 'body'.")
_, data = self.transport.perform_request('GET', _make_path(index, doc_type, '_mget'), _, data = self.transport.perform_request('GET', _make_path(index,
params=params, body=body) doc_type, '_mget'), params=params, body=body)
return data return data
@query_params('consistency', 'fields', 'lang', 'parent', 'refresh', @query_params('consistency', 'fields', 'lang', 'parent', 'refresh',
@@ -398,15 +410,18 @@ class Elasticsearch(object):
:arg doc_type: The type of the document :arg doc_type: The type of the document
:arg id: Document ID :arg id: Document ID
:arg body: The request definition using either `script` or partial `doc` :arg body: The request definition using either `script` or partial `doc`
:arg consistency: Explicit write consistency setting for the operation :arg consistency: Explicit write consistency setting for the operation,
valid choices are: 'one', 'quorum', 'all'
:arg fields: A comma-separated list of fields to return in the response :arg fields: A comma-separated list of fields to return in the response
:arg lang: The script language (default: mvel) :arg lang: The script language (default: groovy)
:arg parent: ID of the parent document :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: Refresh the index after performing the operation
:arg retry_on_conflict: Specify how many times should the operation be :arg retry_on_conflict: Specify how many times should the operation be
retried when a conflict occurs (default: 0) retried when a conflict occurs (default: 0)
:arg routing: Specific routing value :arg routing: Specific routing value
:arg script: The URL-encoded script definition (instead of using request body) :arg script: The URL-encoded script definition (instead of using request
body)
:arg script_id: The id of a stored script :arg script_id: The id of a stored script
:arg scripted_upsert: True if the script referenced in script or :arg scripted_upsert: True if the script referenced in script or
script_id should be called to perform inserts - defaults to false script_id should be called to perform inserts - defaults to false
@@ -414,23 +429,24 @@ class Elasticsearch(object):
:arg timestamp: Explicit timestamp for the document :arg timestamp: Explicit timestamp for the document
:arg ttl: Expiration time for the document :arg ttl: Expiration time for the document
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Explicit version number for concurrency control :arg version_type: Specific version type, valid choices are: 'internal',
'force'
""" """
for param in (index, doc_type, id): for param in (index, doc_type, id):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('POST', _make_path(index, doc_type, id, '_update'), _, data = self.transport.perform_request('POST', _make_path(index,
params=params, body=body) doc_type, id, '_update'), params=params, body=body)
return data return data
@query_params('_source', '_source_exclude', '_source_include', @query_params('_source', '_source_exclude', '_source_include',
'analyze_wildcard', 'analyzer', 'default_operator', 'df', 'allow_no_indices', 'analyze_wildcard', 'analyzer', 'default_operator',
'explain', 'fielddata_fields', 'fields', 'indices_boost', 'lenient', 'df', 'expand_wildcards', 'explain', 'fielddata_fields', 'fields',
'allow_no_indices', 'expand_wildcards', 'ignore_unavailable', 'from_', 'ignore_unavailable', 'lenient', 'lowercase_expanded_terms',
'lowercase_expanded_terms', 'from_', 'preference', 'q', 'query_cache', 'preference', 'q', 'request_cache', 'routing', 'scroll', 'search_type',
'routing', 'scroll', 'search_type', 'size', 'sort', 'source', 'stats', 'size', 'sort', 'stats', 'suggest_field', 'suggest_mode',
'suggest_field', 'suggest_mode', 'suggest_size', 'suggest_text', 'suggest_size', 'suggest_text', 'terminate_after', 'timeout',
'terminate_after', 'timeout', 'track_scores', 'version') 'track_scores', 'version')
def search(self, index=None, doc_type=None, body=None, params=None): 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. Execute a search query and get back search hits that match the query.
@@ -438,8 +454,8 @@ class Elasticsearch(object):
:arg index: A comma-separated list of index names to search; use `_all` :arg index: A comma-separated list of index names to search; use `_all`
or empty string to perform the operation on all indices or empty string to perform the operation on all indices
:arg doc_type: A comma-separated list of document types to search; :arg doc_type: A comma-separated list of document types to search; leave
leave empty to perform the operation on all types empty to perform the operation on all types
:arg body: The search definition using the Query DSL :arg body: The search definition using the Query DSL
:arg _source: True or false to return the _source field or not, or a :arg _source: True or false to return the _source field or not, or a
list of fields to return list of fields to return
@@ -447,54 +463,59 @@ class Elasticsearch(object):
_source field _source field
:arg _source_include: A list of fields to extract and return from the :arg _source_include: A list of fields to extract and return from the
_source field _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 :arg analyze_wildcard: Specify whether wildcard and prefix queries
should be analyzed (default: false) should be analyzed (default: false)
:arg analyzer: The analyzer to use for the query string :arg analyzer: The analyzer to use for the query string
:arg default_operator: The default operator for query string query (AND :arg default_operator: The default operator for query string query (AND
or OR) (default: OR) or OR), default 'OR', valid choices are: 'AND', 'OR'
:arg df: The field to use as default where no field prefix is given in :arg df: The field to use as default where no field prefix is given in
the query string the query string
:arg explain: Specify whether to return detailed information about :arg expand_wildcards: Whether to expand wildcard expression to concrete
score computation as part of a hit 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 :arg fielddata_fields: A comma-separated list of fields to return as the
field data representation of a field for each hit 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 fields: A comma-separated list of fields to return as part of a hit
:arg indices_boost: Comma-separated list of index boosts :arg from_: Starting offset (default: 0)
:arg lenient: Specify whether format-based query failures (such as
providing text to a numeric field) should be ignored
: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'
:arg ignore_unavailable: Whether specified concrete indices should be :arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed) ignored when unavailable (missing or closed)
:arg lowercase_expanded_terms: Specify whether query terms should be lowercased :arg lenient: Specify whether format-based query failures (such as
:arg from\_: Starting offset (default: 0) 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 :arg preference: Specify the node or shard the operation should be
performed on (default: random) performed on (default: random)
:arg q: Query in the Lucene query string syntax :arg q: Query in the Lucene query string syntax
:arg query_cache: Enable or disable caching on a per-query basis :arg request_cache: Specify if request cache should be used for this
request or not, defaults to index level setting
:arg routing: A comma-separated list of specific routing values :arg routing: A comma-separated list of specific routing values
:arg scroll: Specify how long a consistent view of the index should be :arg scroll: Specify how long a consistent view of the index should be
maintained for scrolled search maintained for scrolled search
:arg search_type: Search operation type :arg search_type: Search operation type, valid choices are:
'query_then_fetch', 'dfs_query_then_fetch', 'count', 'scan'
:arg size: Number of hits to return (default: 10) :arg size: Number of hits to return (default: 10)
:arg sort: A comma-separated list of <field>:<direction> pairs :arg sort: A comma-separated list of <field>:<direction> pairs
:arg source: The URL-encoded request definition using the Query DSL :arg stats: Specific 'tag' of the request for logging and statistical
(instead of using request body) purposes
:arg stats: Specific 'tag' of the request for logging and statistical purposes
:arg suggest_field: Specify which field to use for suggestions :arg suggest_field: Specify which field to use for suggestions
:arg suggest_mode: Specify suggest mode (default: missing) :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_size: How many suggestions to return in response
:arg suggest_text: The source text for which the suggestions should be returned :arg suggest_text: The source text for which the suggestions should be
returned
:arg terminate_after: The maximum number of documents to collect for :arg terminate_after: The maximum number of documents to collect for
each shard, upon reaching which the query execution will terminate each shard, upon reaching which the query execution will terminate
early. early.
:arg timeout: Explicit operation timeout :arg timeout: Explicit operation timeout
:arg track_scores: Whether to calculate and return scores even if they :arg track_scores: Whether to calculate and return scores even if they
are not used for sorting are not used for sorting
:arg version: Specify whether to return document version as part of a hit :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 # from is a reserved word so it cannot be used, use from_ instead
if 'from_' in params: if 'from_' in params:
@@ -502,8 +523,8 @@ class Elasticsearch(object):
if doc_type and not index: if doc_type and not index:
index = '_all' index = '_all'
_, data = self.transport.perform_request('GET', _make_path(index, doc_type, '_search'), _, data = self.transport.perform_request('GET', _make_path(index,
params=params, body=body) doc_type, '_search'), params=params, body=body)
return data return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable', @query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
@@ -513,7 +534,7 @@ class Elasticsearch(object):
The search shards api returns the indices and shards that a search The search shards api returns the indices and shards that a search
request would be executed against. This can give useful feedback for working request would be executed against. This can give useful feedback for working
out issues or planning optimizations with routing and shard preferences. out issues or planning optimizations with routing and shard preferences.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-shards.html>`_
:arg index: The name of the index :arg index: The name of the index
:arg doc_type: The type of the document :arg doc_type: The type of the document
@@ -521,7 +542,8 @@ class Elasticsearch(object):
expression resolves into no concrete indices. (This includes `_all` expression resolves into no concrete indices. (This includes `_all`
string or when no indices have been specified) string or when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete :arg expand_wildcards: Whether to expand wildcard expression to concrete
indices that are open, closed or both. (default: '"open"') 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 :arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed) ignored when unavailable (missing or closed)
:arg local: Return local information, do not retrieve the state from :arg local: Return local information, do not retrieve the state from
@@ -540,7 +562,7 @@ class Elasticsearch(object):
""" """
A query that accepts a query template and a map of key/value pairs to A query that accepts a query template and a map of key/value pairs to
fill in template parameters. fill in template parameters.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-template-query.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html>`_
:arg index: A comma-separated list of index names to search; use `_all` :arg index: A comma-separated list of index names to search; use `_all`
or empty string to perform the operation on all indices or empty string to perform the operation on all indices
@@ -551,7 +573,8 @@ class Elasticsearch(object):
expression resolves into no concrete indices. (This includes `_all` expression resolves into no concrete indices. (This includes `_all`
string or when no indices have been specified) string or when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete :arg expand_wildcards: Whether to expand wildcard expression to concrete
indices that are open, closed or both., default 'open' 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 :arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed) ignored when unavailable (missing or closed)
:arg preference: Specify the node or shard the operation should be :arg preference: Specify the node or shard the operation should be
@@ -559,7 +582,9 @@ class Elasticsearch(object):
:arg routing: A comma-separated list of specific routing values :arg routing: A comma-separated list of specific routing values
:arg scroll: Specify how long a consistent view of the index should be :arg scroll: Specify how long a consistent view of the index should be
maintained for scrolled search maintained for scrolled search
:arg search_type: Search operation type :arg search_type: Search operation type, valid choices are:
'query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch',
'dfs_query_and_fetch', 'count', 'scan'
""" """
_, data = self.transport.perform_request('GET', _make_path(index, _, data = self.transport.perform_request('GET', _make_path(index,
doc_type, '_search', 'template'), params=params, body=body) doc_type, '_search', 'template'), params=params, body=body)
@@ -568,7 +593,7 @@ class Elasticsearch(object):
@query_params('_source', '_source_exclude', '_source_include', @query_params('_source', '_source_exclude', '_source_include',
'analyze_wildcard', 'analyzer', 'default_operator', 'df', 'fields', 'analyze_wildcard', 'analyzer', 'default_operator', 'df', 'fields',
'lenient', 'lowercase_expanded_terms', 'parent', 'preference', 'q', 'lenient', 'lowercase_expanded_terms', 'parent', 'preference', 'q',
'routing', 'source') 'routing')
def explain(self, index, doc_type, id, body=None, params=None): def explain(self, index, doc_type, id, body=None, params=None):
""" """
The explain api computes a score explanation for a query and a specific The explain api computes a score explanation for a query and a specific
@@ -590,25 +615,24 @@ class Elasticsearch(object):
the query string query should be analyzed (default: false) the query string query should be analyzed (default: false)
:arg analyzer: The analyzer for the query string query :arg analyzer: The analyzer for the query string query
:arg default_operator: The default operator for query string query (AND :arg default_operator: The default operator for query string query (AND
or OR), (default: OR) or OR), default 'OR', valid choices are: 'AND', 'OR'
:arg df: The default field for query string query (default: _all) :arg df: The default field for query string query (default: _all)
:arg fields: A comma-separated list of fields to return in the response :arg fields: A comma-separated list of fields to return in the response
:arg lenient: Specify whether format-based query failures (such as :arg lenient: Specify whether format-based query failures (such as
providing text to a numeric field) should be ignored providing text to a numeric field) should be ignored
:arg lowercase_expanded_terms: Specify whether query terms should be lowercased :arg lowercase_expanded_terms: Specify whether query terms should be
lowercased
:arg parent: The ID of the parent document :arg parent: The ID of the parent document
:arg preference: Specify the node or shard the operation should be :arg preference: Specify the node or shard the operation should be
performed on (default: random) performed on (default: random)
:arg q: Query in the Lucene query string syntax :arg q: Query in the Lucene query string syntax
:arg routing: Specific routing value :arg routing: Specific routing value
:arg source: The URL-encoded query definition (instead of using the
request body)
""" """
for param in (index, doc_type, id): for param in (index, doc_type, id):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path(index, doc_type, id, '_explain'), _, data = self.transport.perform_request('GET', _make_path(index,
params=params, body=body) doc_type, id, '_explain'), params=params, body=body)
return data return data
@query_params('scroll') @query_params('scroll')
@@ -618,7 +642,7 @@ class Elasticsearch(object):
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html>`_
:arg scroll_id: The scroll ID :arg scroll_id: The scroll ID
:arg body: The scroll ID if not passed by URL or query parameter :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 :arg scroll: Specify how long a consistent view of the index should be
maintained for scrolled search maintained for scrolled search
""" """
@@ -640,12 +664,12 @@ class Elasticsearch(object):
search. search.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html>`_
:arg scroll_id: The scroll ID or a list of scroll IDs :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 :arg body: A comma-separated list of scroll IDs to clear if none was
specified via the scroll_id parameter specified via the scroll_id parameter
""" """
_, data = self.transport.perform_request('DELETE', _make_path('_search', 'scroll', scroll_id), _, data = self.transport.perform_request('DELETE', _make_path('_search',
body=body, params=params) 'scroll', scroll_id), params=params, body=body)
return data return data
@query_params('consistency', 'parent', 'refresh', 'routing', 'timeout', @query_params('consistency', 'parent', 'refresh', 'routing', 'timeout',
@@ -658,24 +682,27 @@ class Elasticsearch(object):
:arg index: The name of the index :arg index: The name of the index
:arg doc_type: The type of the document :arg doc_type: The type of the document
:arg id: The document ID :arg id: The document ID
:arg consistency: Specific write consistency setting for the operation :arg consistency: Specific write consistency setting for the operation,
valid choices are: 'one', 'quorum', 'all'
:arg parent: ID of parent document :arg parent: ID of parent document
:arg refresh: Refresh the index after performing the operation :arg refresh: Refresh the index after performing the operation
:arg routing: Specific routing value :arg routing: Specific routing value
:arg timeout: Explicit operation timeout :arg timeout: Explicit operation timeout
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Specific version type :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
for param in (index, doc_type, id): for param in (index, doc_type, id):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('DELETE', _make_path(index, doc_type, id), params=params) _, data = self.transport.perform_request('DELETE', _make_path(index,
doc_type, id), params=params)
return data return data
@query_params('allow_no_indices', 'analyze_wildcard', 'analyzer', @query_params('allow_no_indices', 'analyze_wildcard', 'analyzer',
'default_operator', 'df', 'expand_wildcards', 'ignore_unavailable', 'default_operator', 'df', 'expand_wildcards', 'ignore_unavailable',
'min_score', 'lenient', 'lowercase_expanded_terms', 'min_score', 'lenient', 'lowercase_expanded_terms', 'min_score', 'preference', 'q',
'preference', 'q', 'routing') 'routing')
def count(self, index=None, doc_type=None, body=None, params=None): def count(self, index=None, doc_type=None, body=None, params=None):
""" """
Execute a query and get the number of matches for that query. Execute a query and get the number of matches for that query.
@@ -683,7 +710,8 @@ class Elasticsearch(object):
:arg index: A comma-separated list of indices to restrict the results :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 doc_type: A comma-separated list of types to restrict the results
:arg body: A query to restrict the results (optional) :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 :arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` expression resolves into no concrete indices. (This includes `_all`
string or when no indices have been specified) string or when no indices have been specified)
@@ -691,14 +719,14 @@ class Elasticsearch(object):
should be analyzed (default: false) should be analyzed (default: false)
:arg analyzer: The analyzer to use for the query string :arg analyzer: The analyzer to use for the query string
:arg default_operator: The default operator for query string query (AND :arg default_operator: The default operator for query string query (AND
or OR), default u'OR' or OR), default 'OR', valid choices are: 'AND', 'OR'
:arg df: The field to use as default where no field prefix is given in :arg df: The field to use as default where no field prefix is given in
the query string the query string
:arg expand_wildcards: Whether to expand wildcard expression to concrete :arg expand_wildcards: Whether to expand wildcard expression to concrete
indices that are open, closed or both., default 'open' 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 :arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed) ignored when unavailable (missing or closed)
:arg min_score: Include only documents with a specific `_score` value in the result
:arg lenient: Specify whether format-based query failures (such as :arg lenient: Specify whether format-based query failures (such as
providing text to a numeric field) should be ignored providing text to a numeric field) should be ignored
:arg lowercase_expanded_terms: Specify whether query terms should be :arg lowercase_expanded_terms: Specify whether query terms should be
@@ -713,33 +741,36 @@ class Elasticsearch(object):
if doc_type and not index: if doc_type and not index:
index = '_all' index = '_all'
_, data = self.transport.perform_request('POST', _make_path(index, doc_type, '_count'), _, data = self.transport.perform_request('POST', _make_path(index,
params=params, body=body) doc_type, '_count'), params=params, body=body)
return data return data
@query_params('consistency', 'refresh', 'routing', 'timeout') @query_params('consistency', 'fields', 'refresh', 'routing', 'timeout')
def bulk(self, body, index=None, doc_type=None, params=None): def bulk(self, body, index=None, doc_type=None, params=None):
""" """
Perform many index/delete operations in a single API call. Perform many index/delete operations in a single API call.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html>`_
See the :func:`~elasticsearch.helpers.bulk` helper function for a more See the :func:`~elasticsearch.helpers.bulk` helper function for a more
friendly API. friendly API.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html>`_
:arg body: The operation definition and data (action-data pairs), as :arg body: The operation definition and data (action-data pairs),
either a newline separated string, or a sequence of dicts to separated by newlines
serialize (one per row).
:arg index: Default index for items which don't provide one :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 doc_type: Default document type for items which don't provide one
:arg consistency: Explicit write consistency setting for the operation :arg consistency: Explicit write consistency setting for the operation,
valid choices are: 'one', 'quorum', 'all'
:arg doc_type: Default document type for items which don't provide one
:arg fields: Default comma-separated list of fields to return in the
response for updates
:arg refresh: Refresh the index after performing the operation :arg refresh: Refresh the index after performing the operation
:arg routing: Specific routing value :arg routing: Specific routing value
:arg timeout: Explicit operation timeout :arg timeout: Explicit operation timeout
""" """
if body in SKIP_IN_PATH: if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.") raise ValueError("Empty value passed for a required argument 'body'.")
_, data = self.transport.perform_request('POST', _make_path(index, doc_type, '_bulk'), _, data = self.transport.perform_request('POST', _make_path(index,
params=params, body=self._bulk_body(body)) doc_type, '_bulk'), params=params, body=self._bulk_body(body))
return data return data
@query_params('search_type') @query_params('search_type')
@@ -749,16 +780,18 @@ class Elasticsearch(object):
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html>`_
:arg body: The request definitions (metadata-search request definition :arg body: The request definitions (metadata-search request definition
pairs), as either a newline separated string, or a sequence of pairs), separated by newlines
dicts to serialize (one per row).
:arg index: A comma-separated list of index names to use as default :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 doc_type: A comma-separated list of document types to use as
:arg search_type: Search operation type default
:arg search_type: Search operation type, valid choices are:
'query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch',
'dfs_query_and_fetch', 'count', 'scan'
""" """
if body in SKIP_IN_PATH: if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.") raise ValueError("Empty value passed for a required argument 'body'.")
_, data = self.transport.perform_request('GET', _make_path(index, doc_type, '_msearch'), _, data = self.transport.perform_request('GET', _make_path(index,
params=params, body=self._bulk_body(body)) doc_type, '_msearch'), params=params, body=self._bulk_body(body))
return data return data
@query_params('allow_no_indices', 'analyzer', 'consistency', @query_params('allow_no_indices', 'analyzer', 'consistency',
@@ -803,16 +836,18 @@ class Elasticsearch(object):
""" """
The suggest feature suggests similar looking terms based on a provided The suggest feature suggests similar looking terms based on a provided
text by using a suggester. text by using a suggester.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html>`_
: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 body: The request definition :arg body: The request definition
: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 allow_no_indices: Whether to ignore if a wildcard indices :arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` expression resolves into no concrete indices. (This includes `_all`
string or when no indices have been specified) string or when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete :arg expand_wildcards: Whether to expand wildcard expression to concrete
indices that are open, closed or both., default 'open' 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 :arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed) ignored when unavailable (missing or closed)
:arg preference: Specify the node or shard the operation should be :arg preference: Specify the node or shard the operation should be
@@ -821,8 +856,8 @@ class Elasticsearch(object):
""" """
if body in SKIP_IN_PATH: if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.") raise ValueError("Empty value passed for a required argument 'body'.")
_, data = self.transport.perform_request('POST', _make_path(index, '_suggest'), _, data = self.transport.perform_request('POST', _make_path(index,
params=params, body=body) '_suggest'), params=params, body=body)
return data return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable', @query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
@@ -847,11 +882,12 @@ class Elasticsearch(object):
expression resolves into no concrete indices. (This includes `_all` expression resolves into no concrete indices. (This includes `_all`
string or when no indices have been specified) string or when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete :arg expand_wildcards: Whether to expand wildcard expression to concrete
indices that are open, closed or both., default 'open' 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 :arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed) ignored when unavailable (missing or closed)
:arg percolate_format: Return an array of matching query IDs instead of :arg percolate_format: Return an array of matching query IDs instead of
objects objects, valid choices are: 'ids'
:arg percolate_index: The index to percolate the document into. Defaults :arg percolate_index: The index to percolate the document into. Defaults
to index. to index.
:arg percolate_preference: Which shard to prefer when executing the :arg percolate_preference: Which shard to prefer when executing the
@@ -864,7 +900,8 @@ class Elasticsearch(object):
performed on (default: random) performed on (default: random)
:arg routing: A comma-separated list of specific routing values :arg routing: A comma-separated list of specific routing values
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Specific version type :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
for param in (index, doc_type): for param in (index, doc_type):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
@@ -881,17 +918,18 @@ class Elasticsearch(object):
queries that match on that doc out of the set of registered queries. queries that match on that doc out of the set of registered queries.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-percolate.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-percolate.html>`_
:arg body: The percolate request definitions (header & body pair),
separated by newlines
:arg index: The index of the document being count percolated to use as :arg index: The index of the document being count percolated to use as
default default
:arg doc_type: The type of the document being percolated to use as :arg doc_type: The type of the document being percolated to use as
default. default.
:arg body: The percolate request definitions (header & body pair),
separated by newlines
:arg allow_no_indices: Whether to ignore if a wildcard indices :arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` expression resolves into no concrete indices. (This includes `_all`
string or when no indices have been specified) string or when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete :arg expand_wildcards: Whether to expand wildcard expression to concrete
indices that are open, closed or both., default 'open' 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 :arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed) ignored when unavailable (missing or closed)
""" """
@@ -923,7 +961,8 @@ class Elasticsearch(object):
expression resolves into no concrete indices. (This includes `_all` expression resolves into no concrete indices. (This includes `_all`
string or when no indices have been specified) string or when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete :arg expand_wildcards: Whether to expand wildcard expression to concrete
indices that are open, closed or both., default 'open' 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 :arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed) ignored when unavailable (missing or closed)
:arg percolate_index: The index to count percolate the document into. :arg percolate_index: The index to count percolate the document into.
@@ -934,7 +973,8 @@ class Elasticsearch(object):
performed on (default: random) performed on (default: random)
:arg routing: A comma-separated list of specific routing values :arg routing: A comma-separated list of specific routing values
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Specific version type :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
for param in (index, doc_type): for param in (index, doc_type):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
@@ -1003,7 +1043,7 @@ class Elasticsearch(object):
artificially provided by the user (Added in 1.4). Note that for 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 documents stored in the index, this is a near realtime API as the term
vectors are not available until the next refresh. vectors are not available until the next refresh.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html>` `<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html>`_
:arg index: The index in which the document resides. :arg index: The index in which the document resides.
:arg doc_type: The type of the document. :arg doc_type: The type of the document.
@@ -1032,39 +1072,29 @@ class Elasticsearch(object):
:arg term_statistics: Specifies if total term frequency and document :arg term_statistics: Specifies if total term frequency and document
frequency should be returned., default False frequency should be returned., default False
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Specific version type :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
for param in (index, doc_type, id): for param in (index, doc_type):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path(index, _, data = self.transport.perform_request('GET', _make_path(index,
doc_type, id, '_termvectors'), params=params, body=body) doc_type, id, '_termvectors'), params=params, body=body)
return data return data
@query_params('field_statistics', 'fields', 'offsets', 'parent', 'payloads',
'positions', 'preference', 'realtime', 'routing', 'term_statistics')
def termvector(self, index, doc_type, id, body=None, params=None):
for param in (index, doc_type, id):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path(index,
doc_type, id, '_termvector'), params=params, body=body)
return data
termvector.__doc__ = termvectors.__doc__
@query_params('field_statistics', 'fields', 'ids', 'offsets', 'parent', @query_params('field_statistics', 'fields', 'ids', 'offsets', 'parent',
'payloads', 'positions', 'preference', 'realtime', 'routing', 'payloads', 'positions', 'preference', 'realtime', 'routing',
'term_statistics') 'term_statistics', 'version', 'version_type')
def mtermvectors(self, index=None, doc_type=None, body=None, params=None): def mtermvectors(self, index=None, doc_type=None, body=None, params=None):
""" """
Multi termvectors API allows to get multiple termvectors based on an Multi termvectors API allows to get multiple termvectors based on an
index, type and id. index, type and id.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html>`_
:arg index: The index in which the document resides. :arg index: The index in which the document resides.
:arg doc_type: The type of the document. :arg doc_type: The type of the document.
:arg body: Define ids, parameters or a list of parameters per document :arg body: Define ids, documents, parameters or a list of parameters per
here. You must at least provide a list of document ids. See document here. You must at least provide a list of document ids. See
documentation. documentation.
:arg field_statistics: Specifies if document count, sum of document :arg field_statistics: Specifies if document count, sum of document
frequencies and sum of total term frequencies should be returned. frequencies and sum of total term frequencies should be returned.
@@ -1097,6 +1127,9 @@ class Elasticsearch(object):
frequency should be returned. Applies to all returned documents frequency should be returned. Applies to all returned documents
unless otherwise specified in body "params" or "docs"., default unless otherwise specified in body "params" or "docs"., default
False False
:arg version: Explicit version number for concurrency control
:arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
_, data = self.transport.perform_request('GET', _make_path(index, _, data = self.transport.perform_request('GET', _make_path(index,
doc_type, '_mtermvectors'), params=params, body=body) doc_type, '_mtermvectors'), params=params, body=body)
@@ -1111,9 +1144,11 @@ class Elasticsearch(object):
:arg lang: Script language :arg lang: Script language
:arg id: Script ID :arg id: Script ID
:arg body: The document :arg body: The document
:arg op_type: Explicit operation type, default u'index' :arg op_type: Explicit operation type, default 'index', valid choices
are: 'index', 'create'
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Specific version type :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
for param in (lang, id, body): for param in (lang, id, body):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
@@ -1131,7 +1166,8 @@ class Elasticsearch(object):
:arg lang: Script language :arg lang: Script language
:arg id: Script ID :arg id: Script ID
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Specific version type :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
for param in (lang, id): for param in (lang, id):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
@@ -1149,7 +1185,8 @@ class Elasticsearch(object):
:arg lang: Script language :arg lang: Script language
:arg id: Script ID :arg id: Script ID
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Specific version type :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
for param in (lang, id): for param in (lang, id):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
@@ -1166,9 +1203,11 @@ class Elasticsearch(object):
:arg id: Template ID :arg id: Template ID
:arg body: The document :arg body: The document
:arg op_type: Explicit operation type, default u'index' :arg op_type: Explicit operation type, default 'index', valid choices
are: 'index', 'create'
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Specific version type :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
for param in (id, body): for param in (id, body):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
@@ -1185,12 +1224,13 @@ class Elasticsearch(object):
:arg id: Template ID :arg id: Template ID
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Specific version type :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
if id in SKIP_IN_PATH: if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'id'.") raise ValueError("Empty value passed for a required argument 'id'.")
_, data = self.transport.perform_request('GET', _make_path('_search', 'template', _, data = self.transport.perform_request('GET', _make_path('_search',
id), params=params) 'template', id), params=params)
return data return data
@query_params('version', 'version_type') @query_params('version', 'version_type')
@@ -1201,7 +1241,8 @@ class Elasticsearch(object):
:arg id: Template ID :arg id: Template ID
:arg version: Explicit version number for concurrency control :arg version: Explicit version number for concurrency control
:arg version_type: Specific version type :arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
""" """
_, data = self.transport.perform_request('DELETE', _make_path('_search', _, data = self.transport.perform_request('DELETE', _make_path('_search',
'template', id), params=params) 'template', id), params=params)
@@ -1228,11 +1269,12 @@ class Elasticsearch(object):
should be analyzed (default: false) should be analyzed (default: false)
:arg analyzer: The analyzer to use for the query string :arg analyzer: The analyzer to use for the query string
:arg default_operator: The default operator for query string query (AND :arg default_operator: The default operator for query string query (AND
or OR), default u'OR' or OR), default 'OR', valid choices are: 'AND', 'OR'
:arg df: The field to use as default where no field prefix is given in :arg df: The field to use as default where no field prefix is given in
the query string the query string
:arg expand_wildcards: Whether to expand wildcard expression to concrete :arg expand_wildcards: Whether to expand wildcard expression to concrete
indices that are open, closed or both., default u'open' 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 :arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed) ignored when unavailable (missing or closed)
:arg lenient: Specify whether format-based query failures (such as :arg lenient: Specify whether format-based query failures (such as
@@ -1246,37 +1288,51 @@ class Elasticsearch(object):
:arg q: Query in the Lucene query string syntax :arg q: Query in the Lucene query string syntax
:arg routing: Specific routing value :arg routing: Specific routing value
""" """
try: _, data = self.transport.perform_request('POST', _make_path(index,
self.transport.perform_request('POST', _make_path(index, doc_type, '_search', 'exists'), params=params, body=body)
doc_type, '_search', 'exists'), params=params, body=body) return data
except NotFoundError:
return False
return True
@query_params('allow_no_indices', 'expand_wildcards', 'fields', @query_params('allow_no_indices', 'expand_wildcards', 'fields',
'ignore_unavailable', 'level') 'ignore_unavailable', 'level')
def field_stats(self, index=None, params=None): def field_stats(self, index=None, body=None, params=None):
""" """
The field stats api allows one to find statistical properties of a The field stats api allows one to find statistical properties of a
field without executing a search, but looking up measurements that are field without executing a search, but looking up measurements that are
natively available in the Lucene index. natively available in the Lucene index.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-stats.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-field-stats.html>`_
:arg index: A comma-separated list of index names; use `_all` or empty :arg index: A comma-separated list of index names; use `_all` or empty
string to perform the operation on all indices string to perform the operation on all indices
:arg body: Field json objects containing the name and optionally a range
to filter out indices result, that have results outside the defined
bounds
:arg allow_no_indices: Whether to ignore if a wildcard indices :arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` expression resolves into no concrete indices. (This includes `_all`
string or when no indices have been specified) string or when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete :arg expand_wildcards: Whether to expand wildcard expression to concrete
indices that are open, closed or both., default u'open' indices that are open, closed or both., default 'open', valid
choices are: 'open', 'closed', 'none', 'all'
:arg fields: A comma-separated list of fields for to get field :arg fields: A comma-separated list of fields for to get field
statistics for (min value, max value, and more) statistics for (min value, max value, and more)
:arg ignore_unavailable: Whether specified concrete indices should be :arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed) ignored when unavailable (missing or closed)
:arg level: Defines if field stats should be returned on a per index :arg level: Defines if field stats should be returned on a per index
level or on a cluster wide level, default u'cluster' level or on a cluster wide level, default 'cluster', valid choices
are: 'indices', 'cluster'
""" """
_, data = self.transport.perform_request('GET', _make_path(index, _, data = self.transport.perform_request('GET', _make_path(index,
'_field_stats'), params=params) '_field_stats'), params=params, body=body)
return data
@query_params()
def render_search_template(self, id=None, body=None, params=None):
"""
`<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-template.html>`_
:arg id: The id of the stored search template
:arg body: The search definition template and its params
"""
_, data = self.transport.perform_request('GET', _make_path('_render',
'template', id), params=params, body=body)
return data return data
+63 -53
View File
@@ -4,7 +4,8 @@ class CatClient(NamespacedClient):
@query_params('h', 'help', 'local', 'master_timeout', 'v') @query_params('h', 'help', 'local', 'master_timeout', 'v')
def aliases(self, name=None, params=None): def aliases(self, name=None, params=None):
""" """
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-alias.html>`_
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-alias.html>`_
:arg name: A comma-separated list of alias names to return :arg name: A comma-separated list of alias names to return
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
@@ -13,7 +14,7 @@ class CatClient(NamespacedClient):
master node (default: false) master node (default: false)
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg v: Verbose mode. Display column headers, default False :arg v: Verbose mode. Display column headers, default True
""" """
_, data = self.transport.perform_request('GET', _make_path('_cat', _, data = self.transport.perform_request('GET', _make_path('_cat',
'aliases', name), params=params) 'aliases', name), params=params)
@@ -24,18 +25,19 @@ class CatClient(NamespacedClient):
""" """
Allocation provides a snapshot of how shards have located around the Allocation provides a snapshot of how shards have located around the
cluster and the state of disk usage. cluster and the state of disk usage.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-allocation.html>`_
:arg node_id: A comma-separated list of node IDs or names to limit the :arg node_id: A comma-separated list of node IDs or names to limit the
returned information returned information
:arg bytes: The unit in which to display byte values :arg bytes: The unit in which to display byte values, valid choices are:
'b', 'k', 'm', 'g'
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
:arg help: Return help information, default False :arg help: Return help information, default False
:arg local: Return local information, do not retrieve the state from :arg local: Return local information, do not retrieve the state from
master node (default: false) master node (default: false)
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg v: Verbose mode. Display column headers, default False :arg v: Verbose mode. Display column headers, default True
""" """
_, data = self.transport.perform_request('GET', _make_path('_cat', _, data = self.transport.perform_request('GET', _make_path('_cat',
'allocation', node_id), params=params) 'allocation', node_id), params=params)
@@ -46,7 +48,7 @@ class CatClient(NamespacedClient):
""" """
Count provides quick access to the document count of the entire cluster, Count provides quick access to the document count of the entire cluster,
or individual indices. or individual indices.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-count.html>`_
:arg index: A comma-separated list of index names to limit the returned :arg index: A comma-separated list of index names to limit the returned
information information
@@ -56,7 +58,7 @@ class CatClient(NamespacedClient):
master node (default: false) master node (default: false)
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg v: Verbose mode. Display column headers, default False :arg v: Verbose mode. Display column headers, default True
""" """
_, data = self.transport.perform_request('GET', _make_path('_cat', _, data = self.transport.perform_request('GET', _make_path('_cat',
'count', index), params=params) 'count', index), params=params)
@@ -67,7 +69,7 @@ class CatClient(NamespacedClient):
""" """
health is a terse, one-line representation of the same information from health is a terse, one-line representation of the same information from
:meth:`~elasticsearch.client.cluster.ClusterClient.health` API :meth:`~elasticsearch.client.cluster.ClusterClient.health` API
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-health.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-health.html>`_
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
:arg help: Return help information, default False :arg help: Return help information, default False
@@ -76,7 +78,7 @@ class CatClient(NamespacedClient):
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg ts: Set to false to disable timestamping, default True :arg ts: Set to false to disable timestamping, default True
:arg v: Verbose mode. Display column headers, default False :arg v: Verbose mode. Display column headers, default True
""" """
_, data = self.transport.perform_request('GET', '/_cat/health', _, data = self.transport.perform_request('GET', '/_cat/health',
params=params) params=params)
@@ -86,7 +88,7 @@ class CatClient(NamespacedClient):
def help(self, params=None): def help(self, params=None):
""" """
A simple help for the cat api. A simple help for the cat api.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat.html>`_
:arg help: Return help information, default False :arg help: Return help information, default False
""" """
@@ -97,11 +99,12 @@ class CatClient(NamespacedClient):
def indices(self, index=None, params=None): def indices(self, index=None, params=None):
""" """
The indices command provides a cross-section of each index. The indices command provides a cross-section of each index.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html>`_
:arg index: A comma-separated list of index names to limit the returned :arg index: A comma-separated list of index names to limit the returned
information information
:arg bytes: The unit in which to display byte values :arg bytes: The unit in which to display byte values, valid choices are:
'b', 'k', 'm', 'g'
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
:arg help: Return help information, default False :arg help: Return help information, default False
:arg local: Return local information, do not retrieve the state from :arg local: Return local information, do not retrieve the state from
@@ -110,7 +113,7 @@ class CatClient(NamespacedClient):
node node
:arg pri: Set to true to return stats only for primary shards, default :arg pri: Set to true to return stats only for primary shards, default
False False
:arg v: Verbose mode. Display column headers, default False :arg v: Verbose mode. Display column headers, default True
""" """
_, data = self.transport.perform_request('GET', _make_path('_cat', _, data = self.transport.perform_request('GET', _make_path('_cat',
'indices', index), params=params) 'indices', index), params=params)
@@ -120,7 +123,7 @@ class CatClient(NamespacedClient):
def master(self, params=None): def master(self, params=None):
""" """
Displays the master's node ID, bound IP address, and node name. Displays the master's node ID, bound IP address, and node name.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-master.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-master.html>`_
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
:arg help: Return help information, default False :arg help: Return help information, default False
@@ -128,90 +131,81 @@ class CatClient(NamespacedClient):
master node (default: false) master node (default: false)
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg v: Verbose mode. Display column headers, default False :arg v: Verbose mode. Display column headers, default True
""" """
_, data = self.transport.perform_request('GET', '/_cat/master', _, data = self.transport.perform_request('GET', '/_cat/master',
params=params) params=params)
return data return data
@query_params('bytes', 'h', 'help', 'local', 'master_timeout', 'time', 'v') @query_params('h', 'help', 'local', 'master_timeout', 'v')
def nodes(self, params=None): def nodes(self, params=None):
""" """
The nodes command shows the cluster topology. The nodes command shows the cluster topology.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodes.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html>`_
:arg bytes: The unit in which to display byte values
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
:arg help: Return help information, default False :arg help: Return help information, default False
:arg local: Return local information, do not retrieve the state from :arg local: Return local information, do not retrieve the state from
master node (default: false) master node (default: false)
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg time: The unit in which to display time values :arg v: Verbose mode. Display column headers, default True
:arg v: Verbose mode. Display column headers, default False
""" """
_, data = self.transport.perform_request('GET', '/_cat/nodes', _, data = self.transport.perform_request('GET', '/_cat/nodes',
params=params) params=params)
return data return data
@query_params('bytes', 'h', 'help', 'local', 'master_timeout', 'v') @query_params('bytes', 'h', 'help', 'master_timeout', 'v')
def recovery(self, index=None, params=None): def recovery(self, index=None, params=None):
""" """
recovery is a view of shard replication. recovery is a view of shard replication.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-recovery.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-recovery.html>`_
:arg index: A comma-separated list of index names to limit the returned :arg index: A comma-separated list of index names to limit the returned
information information
:arg bytes: The unit in which to display byte values :arg bytes: The unit in which to display byte values, valid choices are:
'b', 'k', 'm', 'g'
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
:arg help: Return help information, default False :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 :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg v: Verbose mode. Display column headers, default False :arg v: Verbose mode. Display column headers, default True
""" """
_, data = self.transport.perform_request('GET', _make_path('_cat', _, data = self.transport.perform_request('GET', _make_path('_cat',
'recovery', index), params=params) 'recovery', index), params=params)
return data return data
@query_params('bytes', 'h', 'help', 'local', 'master_timeout', 'v') @query_params('h', 'help', 'local', 'master_timeout', 'v')
def shards(self, index=None, params=None): def shards(self, index=None, params=None):
""" """
The shards command is the detailed view of what nodes contain which shards. The shards command is the detailed view of what nodes contain which shards.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-shards.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-shards.html>`_
:arg index: A comma-separated list of index names to limit the returned :arg index: A comma-separated list of index names to limit the returned
information information
:arg bytes: The unit in which to display byte values
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
:arg help: Return help information, default False :arg help: Return help information, default False
:arg local: Return local information, do not retrieve the state from :arg local: Return local information, do not retrieve the state from
master node (default: false) master node (default: false)
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg v: Verbose mode. Display column headers, default False :arg v: Verbose mode. Display column headers, default True
""" """
_, data = self.transport.perform_request('GET', _make_path('_cat', _, data = self.transport.perform_request('GET', _make_path('_cat',
'shards', index), params=params) 'shards', index), params=params)
return data return data
@query_params('bytes', 'h', 'help', 'local', 'master_timeout', 'v') @query_params('h', 'help', 'v')
def segments(self, index=None, params=None): def segments(self, index=None, params=None):
""" """
The segments command is the detailed view of Lucene segments per index. The segments command is the detailed view of Lucene segments per index.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-segments.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-segments.html>`_
:arg index: A comma-separated list of index names to limit the returned :arg index: A comma-separated list of index names to limit the returned
information information
:arg bytes: The unit in which to display byte values
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
:arg help: Return help information, default False :arg help: Return help information, default False
:arg local: Return local information, do not retrieve the state from :arg v: Verbose mode. Display column headers, default True
master node (default: false)
:arg master_timeout: Explicit operation timeout for connection to master
node
:arg v: Verbose mode. Display column headers, default False
""" """
_, data = self.transport.perform_request('GET', _make_path('_cat', _, data = self.transport.perform_request('GET', _make_path('_cat',
'segments', index), params=params) 'segments', index), params=params)
@@ -223,7 +217,7 @@ class CatClient(NamespacedClient):
pending_tasks provides the same information as the pending_tasks provides the same information as the
:meth:`~elasticsearch.client.cluster.ClusterClient.pending_tasks` API :meth:`~elasticsearch.client.cluster.ClusterClient.pending_tasks` API
in a convenient tabular format. in a convenient tabular format.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-pending-tasks.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-pending-tasks.html>`_
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
:arg help: Return help information, default False :arg help: Return help information, default False
@@ -231,7 +225,7 @@ class CatClient(NamespacedClient):
master node (default: false) master node (default: false)
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg v: Verbose mode. Display column headers, default False :arg v: Verbose mode. Display column headers, default True
""" """
_, data = self.transport.perform_request('GET', '/_cat/pending_tasks', _, data = self.transport.perform_request('GET', '/_cat/pending_tasks',
params=params) params=params)
@@ -241,17 +235,16 @@ class CatClient(NamespacedClient):
def thread_pool(self, params=None): def thread_pool(self, params=None):
""" """
Get information about thread pools. Get information about thread pools.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-thread-pool.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-thread-pool.html>`_
:arg full_id: Enables displaying the complete node ids (default: 'false') :arg full_id: Enables displaying the complete node ids, default False
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
:arg help: Return help information (default: 'false') :arg help: Return help information, default False
:arg local: Return local information, do not retrieve the state from :arg local: Return local information, do not retrieve the state from
master node (default: false) master node (default: false)
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg v: Verbose mode. Display column headers (default: 'false') :arg v: Verbose mode. Display column headers, default True
""" """
_, data = self.transport.perform_request('GET', '/_cat/thread_pool', _, data = self.transport.perform_request('GET', '/_cat/thread_pool',
params=params) params=params)
@@ -262,21 +255,20 @@ class CatClient(NamespacedClient):
def fielddata(self, fields=None, params=None): def fielddata(self, fields=None, params=None):
""" """
Shows information about currently loaded fielddata on a per-node basis. Shows information about currently loaded fielddata on a per-node basis.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-fielddata.html>`_
:arg fields: A comma-separated list of fields to return the fielddata :arg fields: A comma-separated list of fields to return the fielddata
size size
:arg bytes: The unit in which to display byte values :arg bytes: The unit in which to display byte values, valid choices are:
:arg fields: A comma-separated list of fields to return the fielddata 'b', 'k', 'm', 'g'
size :arg fields: A comma-separated list of fields to return in the output
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
:arg help: Return help information (default: 'false') :arg help: Return help information, default False
:arg local: Return local information, do not retrieve the state from :arg local: Return local information, do not retrieve the state from
master node (default: false) master node (default: false)
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg v: Verbose mode. Display column headers (default: 'false') :arg v: Verbose mode. Display column headers, default True
""" """
_, data = self.transport.perform_request('GET', _make_path('_cat', _, data = self.transport.perform_request('GET', _make_path('_cat',
'fielddata', fields), params=params) 'fielddata', fields), params=params)
@@ -285,6 +277,7 @@ class CatClient(NamespacedClient):
@query_params('h', 'help', 'local', 'master_timeout', 'v') @query_params('h', 'help', 'local', 'master_timeout', 'v')
def plugins(self, params=None): def plugins(self, params=None):
""" """
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-plugins.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-plugins.html>`_
:arg h: Comma-separated list of column names to display :arg h: Comma-separated list of column names to display
@@ -293,9 +286,26 @@ class CatClient(NamespacedClient):
master node (default: false) master node (default: false)
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg v: Verbose mode. Display column headers, default False :arg v: Verbose mode. Display column headers, default True
""" """
_, data = self.transport.perform_request('GET', '/_cat/plugins', _, data = self.transport.perform_request('GET', '/_cat/plugins',
params=params) params=params)
return data return data
@query_params('h', 'help', 'local', 'master_timeout', 'v')
def nodeattrs(self, params=None):
"""
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodeattrs.html>`_
: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 v: Verbose mode. Display column headers, default True
"""
_, data = self.transport.perform_request('GET', '/_cat/nodeattrs',
params=params)
return data
+50 -34
View File
@@ -2,25 +2,32 @@ from .utils import NamespacedClient, query_params, _make_path
class ClusterClient(NamespacedClient): class ClusterClient(NamespacedClient):
@query_params('level', 'local', 'master_timeout', 'timeout', @query_params('level', 'local', 'master_timeout', 'timeout',
'wait_for_active_shards', 'wait_for_nodes', 'wait_for_relocating_shards', 'wait_for_active_shards', 'wait_for_nodes',
'wait_for_status') 'wait_for_relocating_shards', 'wait_for_status')
def health(self, index=None, params=None): def health(self, index=None, params=None):
""" """
Get a very simple status on the health of the cluster. Get a very simple status on the health of the cluster.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html>`_
:arg index: Limit the information returned to a specific index :arg index: Limit the information returned to a specific index
:arg level: Specify the level of detail for returned information, default u'cluster' :arg level: Specify the level of detail for returned information,
:arg local: Return local information, do not retrieve the state from master node (default: false) default 'cluster', valid choices are: 'cluster', 'indices', 'shards'
: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
:arg timeout: Explicit operation timeout :arg timeout: Explicit operation timeout
:arg wait_for_active_shards: Wait until the specified number of shards is active :arg wait_for_active_shards: Wait until the specified number of shards
:arg wait_for_nodes: Wait until the specified number of nodes is available is active
:arg wait_for_relocating_shards: Wait until the specified number of relocating shards is finished :arg wait_for_nodes: Wait until the specified number of nodes is
:arg wait_for_status: Wait until cluster is in a specific state, default None available
:arg wait_for_relocating_shards: Wait until the specified number of
relocating shards is finished
:arg wait_for_status: Wait until cluster is in a specific state, default
None, valid choices are: 'green', 'yellow', 'red'
""" """
_, data = self.transport.perform_request('GET', _make_path('_cluster', 'health', index), _, data = self.transport.perform_request('GET', _make_path('_cluster',
params=params) 'health', index), params=params)
return data return data
@query_params('local', 'master_timeout') @query_params('local', 'master_timeout')
@@ -31,11 +38,12 @@ class ClusterClient(NamespacedClient):
which have not yet been executed. which have not yet been executed.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-pending.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-pending.html>`_
: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 :arg master_timeout: Specify timeout for connection to master
""" """
_, data = self.transport.perform_request('GET', '/_cluster/pending_tasks', _, data = self.transport.perform_request('GET',
params=params) '/_cluster/pending_tasks', params=params)
return data return data
@query_params('allow_no_indices', 'expand_wildcards', 'flat_settings', @query_params('allow_no_indices', 'expand_wildcards', 'flat_settings',
@@ -45,16 +53,15 @@ class ClusterClient(NamespacedClient):
Get a comprehensive state information of the whole cluster. Get a comprehensive state information of the whole cluster.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-state.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-state.html>`_
:arg metric: Limit the information returned to the specified metrics. :arg metric: Limit the information returned to the specified metrics
Possible values: "_all", "blocks", "index_templates", "metadata",
"nodes", "routing_table", "master_node", "version"
:arg index: A comma-separated list of index names; use `_all` or empty :arg index: A comma-separated list of index names; use `_all` or empty
string to perform the operation on all indices string to perform the operation on all indices
:arg allow_no_indices: Whether to ignore if a wildcard indices :arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` expression resolves into no concrete indices. (This includes `_all`
string or when no indices have been specified) string or when no indices have been specified)
:arg expand_wildcards: Whether wildcard expressions should get expanded :arg expand_wildcards: Whether to expand wildcard expression to concrete
to open or closed indices (default: open) 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 flat_settings: Return settings in flat format (default: false)
:arg ignore_unavailable: Whether specified concrete indices should be :arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed) ignored when unavailable (missing or closed)
@@ -64,7 +71,8 @@ class ClusterClient(NamespacedClient):
""" """
if index and not metric: if index and not metric:
metric = '_all' metric = '_all'
_, data = self.transport.perform_request('GET', _make_path('_cluster', 'state', metric, index), params=params) _, data = self.transport.perform_request('GET', _make_path('_cluster',
'state', metric, index), params=params)
return data return data
@query_params('flat_settings', 'human') @query_params('flat_settings', 'human')
@@ -76,11 +84,12 @@ class ClusterClient(NamespacedClient):
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-stats.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-stats.html>`_
:arg node_id: A comma-separated list of node IDs or names to limit the :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 returned information; use `_local` to return information from the
you're connecting to, leave empty to get information from all nodes 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 human: Whether to return time and byte values in human-readable format. :arg human: Whether to return time and byte values in human-readable
format., default False
""" """
url = '/_cluster/stats' url = '/_cluster/stats'
if node_id: if node_id:
@@ -94,16 +103,20 @@ class ClusterClient(NamespacedClient):
Explicitly execute a cluster reroute allocation command including specific commands. Explicitly execute a cluster reroute allocation command including specific commands.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-reroute.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-reroute.html>`_
:arg body: The definition of `commands` to perform (`move`, `cancel`, `allocate`) :arg body: The definition of `commands` to perform (`move`, `cancel`,
`allocate`)
:arg dry_run: Simulate the operation only and return the resulting state :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 explain: Return an explanation of why the commands can or cannot be
:arg filter_metadata: Don't return cluster state metadata (default: false) executed
:arg master_timeout: Explicit operation timeout for connection to master node :arg master_timeout: Explicit operation timeout for connection to master
node
:arg metric: Limit the information returned to the specified metrics. :arg metric: Limit the information returned to the specified metrics.
Defaults to all but metadata Defaults to all but metadata, valid choices are: '_all', 'blocks',
'metadata', 'nodes', 'routing_table', 'master_node', 'version'
:arg timeout: Explicit operation timeout :arg timeout: Explicit operation timeout
""" """
_, data = self.transport.perform_request('POST', '/_cluster/reroute', params=params, body=body) _, data = self.transport.perform_request('POST', '/_cluster/reroute',
params=params, body=body)
return data return data
@query_params('flat_settings', 'master_timeout', 'timeout') @query_params('flat_settings', 'master_timeout', 'timeout')
@@ -113,14 +126,16 @@ class ClusterClient(NamespacedClient):
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html>`_
:arg flat_settings: Return settings in flat format (default: false) :arg flat_settings: Return settings in flat format (default: false)
: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 timeout: Explicit operation timeout
""" """
_, data = self.transport.perform_request('GET', '/_cluster/settings', params=params) _, data = self.transport.perform_request('GET', '/_cluster/settings',
params=params)
return data return data
@query_params('flat_settings', 'master_timeout', 'timeout') @query_params('flat_settings', 'master_timeout', 'timeout')
def put_settings(self, body, params=None): def put_settings(self, body=None, params=None):
""" """
Update cluster wide specific settings. Update cluster wide specific settings.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html>`_
@@ -132,6 +147,7 @@ class ClusterClient(NamespacedClient):
node node
:arg timeout: Explicit operation timeout :arg timeout: Explicit operation timeout
""" """
_, data = self.transport.perform_request('PUT', '/_cluster/settings', params=params, body=body) _, data = self.transport.perform_request('PUT', '/_cluster/settings',
params=params, body=body)
return data return data
File diff suppressed because it is too large Load Diff
+10 -15
View File
@@ -13,8 +13,7 @@ class NodesClient(NamespacedClient):
node you're connecting to, leave empty to get information from all node you're connecting to, leave empty to get information from all
nodes nodes
:arg metric: A comma-separated list of metrics you wish returned. Leave :arg metric: A comma-separated list of metrics you wish returned. Leave
empty to return all. Choices are "settings", "os", "process", empty to return all.
"jvm", "thread_pool", "network", "transport", "http", "plugin"
:arg flat_settings: Return settings in flat format (default: false) :arg flat_settings: Return settings in flat format (default: false)
:arg human: Whether to return time and byte values in human-readable :arg human: Whether to return time and byte values in human-readable
format., default False format., default False
@@ -53,15 +52,10 @@ class NodesClient(NamespacedClient):
returned information; use `_local` to return information from the returned information; use `_local` to return information from the
node you're connecting to, leave empty to get information from all node you're connecting to, leave empty to get information from all
nodes nodes
:arg metric: Limit the information returned to the specified metrics. :arg metric: Limit the information returned to the specified metrics
Possible options are: "_all", "breaker", "fs", "http", "indices",
"jvm", "network", "os", "process", "thread_pool", "transport"
:arg index_metric: Limit the information returned for `indices` metric :arg index_metric: Limit the information returned for `indices` metric
to the specific index metrics. Isn't used if `indices` (or `all`) to the specific index metrics. Isn't used if `indices` (or `all`)
metric isn't specified. Possible options are: "_all", "completion", metric isn't specified.
"docs", "fielddata", "filter_cache", "flush", "get", "id_cache",
"indexing", "merge", "percolate", "refresh", "search", "segments",
"store", "warmer"
:arg completion_fields: A comma-separated list of fields for `fielddata` :arg completion_fields: A comma-separated list of fields for `fielddata`
and `suggest` index metric (supports wildcards) and `suggest` index metric (supports wildcards)
:arg fielddata_fields: A comma-separated list of fields for `fielddata` :arg fielddata_fields: A comma-separated list of fields for `fielddata`
@@ -73,7 +67,8 @@ class NodesClient(NamespacedClient):
:arg human: Whether to return time and byte values in human-readable :arg human: Whether to return time and byte values in human-readable
format., default False format., default False
:arg level: Return indices stats aggregated at node, index or shard :arg level: Return indices stats aggregated at node, index or shard
level, default 'node' level, default 'node', valid choices are: 'node', 'indices',
'shards'
:arg types: A comma-separated list of document types for the `indexing` :arg types: A comma-separated list of document types for the `indexing`
index metric index metric
""" """
@@ -81,7 +76,7 @@ class NodesClient(NamespacedClient):
node_id, 'stats', metric, index_metric), params=params) node_id, 'stats', metric, index_metric), params=params)
return data return data
@query_params('type_', 'ignore_idle_threads', 'interval', 'snapshots', @query_params('doc_type', 'ignore_idle_threads', 'interval', 'snapshots',
'threads') 'threads')
def hot_threads(self, node_id=None, params=None): def hot_threads(self, node_id=None, params=None):
""" """
@@ -92,7 +87,8 @@ class NodesClient(NamespacedClient):
returned information; use `_local` to return information from the returned information; use `_local` to return information from the
node you're connecting to, leave empty to get information from all node you're connecting to, leave empty to get information from all
nodes nodes
:arg type_: The type to sample (default: cpu) :arg doc_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 :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 places, such as waiting on a socket select or pulling from an empty
task queue (default: true) task queue (default: true)
@@ -104,8 +100,7 @@ class NodesClient(NamespacedClient):
# avoid python reserved words # avoid python reserved words
if params and 'type_' in params: if params and 'type_' in params:
params['type'] = params.pop('type_') params['type'] = params.pop('type_')
_, data = self.transport.perform_request('GET', _make_path('_nodes', _, data = self.transport.perform_request('GET', _make_path('_cluster',
node_id, 'hot_threads'), params=params) 'nodes', node_id, 'hotthreads'), params=params)
return data return data
+12 -11
View File
@@ -5,7 +5,7 @@ class SnapshotClient(NamespacedClient):
def create(self, repository, snapshot, body=None, params=None): def create(self, repository, snapshot, body=None, params=None):
""" """
Create a snapshot in repository Create a snapshot in repository
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
:arg repository: A repository name :arg repository: A repository name
:arg snapshot: A snapshot name :arg snapshot: A snapshot name
@@ -26,7 +26,7 @@ class SnapshotClient(NamespacedClient):
def delete(self, repository, snapshot, params=None): def delete(self, repository, snapshot, params=None):
""" """
Deletes a snapshot from a repository. Deletes a snapshot from a repository.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
:arg repository: A repository name :arg repository: A repository name
:arg snapshot: A snapshot name :arg snapshot: A snapshot name
@@ -44,9 +44,9 @@ class SnapshotClient(NamespacedClient):
def get(self, repository, snapshot, params=None): def get(self, repository, snapshot, params=None):
""" """
Retrieve information about a snapshot. Retrieve information about a snapshot.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
:arg repository: A comma-separated list of repository names :arg repository: A repository name
:arg snapshot: A comma-separated list of snapshot names :arg snapshot: A comma-separated list of snapshot names
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
@@ -62,7 +62,7 @@ class SnapshotClient(NamespacedClient):
def delete_repository(self, repository, params=None): def delete_repository(self, repository, params=None):
""" """
Removes a shared file system repository. Removes a shared file system repository.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
:arg repository: A comma-separated list of repository names :arg repository: A comma-separated list of repository names
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
@@ -79,29 +79,30 @@ class SnapshotClient(NamespacedClient):
def get_repository(self, repository=None, params=None): def get_repository(self, repository=None, params=None):
""" """
Return information about registered repositories. Return information about registered repositories.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
:arg repository: A comma-separated list of repository names :arg repository: A comma-separated list of repository names
:arg master_timeout: Explicit operation timeout for connection to master
node
:arg local: Return local information, do not retrieve the state from :arg local: Return local information, do not retrieve the state from
master node (default: false) master node (default: false)
:arg master_timeout: Explicit operation timeout for connection to master
node
""" """
_, data = self.transport.perform_request('GET', _make_path('_snapshot', _, data = self.transport.perform_request('GET', _make_path('_snapshot',
repository), params=params) repository), params=params)
return data return data
@query_params('master_timeout', 'timeout') @query_params('master_timeout', 'timeout', 'verify')
def create_repository(self, repository, body, params=None): def create_repository(self, repository, body, params=None):
""" """
Registers a shared file system repository. Registers a shared file system repository.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
:arg repository: A repository name :arg repository: A repository name
:arg body: The repository definition :arg body: The repository definition
:arg master_timeout: Explicit operation timeout for connection to master :arg master_timeout: Explicit operation timeout for connection to master
node node
:arg timeout: Explicit operation timeout :arg timeout: Explicit operation timeout
:arg verify: Whether to verify the repository after creation
""" """
for param in (repository, body): for param in (repository, body):
if param in SKIP_IN_PATH: if param in SKIP_IN_PATH:
@@ -114,7 +115,7 @@ class SnapshotClient(NamespacedClient):
def restore(self, repository, snapshot, body=None, params=None): def restore(self, repository, snapshot, body=None, params=None):
""" """
Restore a snapshot. Restore a snapshot.
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html>`_ `<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
:arg repository: A repository name :arg repository: A repository name
:arg snapshot: A snapshot name :arg snapshot: A snapshot name
@@ -145,7 +145,8 @@ class TestBulk(ElasticsearchTestCase):
self.assertEquals('42', error['index']['_id']) self.assertEquals('42', error['index']['_id'])
self.assertEquals('t', error['index']['_type']) self.assertEquals('t', error['index']['_type'])
self.assertEquals('i', error['index']['_index']) self.assertEquals('i', error['index']['_index'])
self.assertIn('MapperParsingException', error['index']['error']) print(error['index']['error'])
self.assertTrue('MapperParsingException' in repr(error['index']['error']) or 'mapper_parsing_exception' in repr(error['index']['error']))
def test_error_is_raised(self): def test_error_is_raised(self):
self.client.indices.create("i", self.client.indices.create("i",