Skip to content

Commit

Permalink
Adding new parameters to indices APIs
Browse files Browse the repository at this point in the history
See elastic/elasticsearch#4436 for more details
  • Loading branch information
riki-tanaka committed Jan 2, 2014
1 parent 0cfe2bb commit b195705
Showing 1 changed file with 119 additions and 28 deletions.
147 changes: 119 additions & 28 deletions elasticsearch/client/indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def analyze(self, index=None, body=None, params=None):
params=params, body=body)
return data

@query_params('ignore_indices')
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_indices', 'ignore_unavailable')
def refresh(self, index=None, params=None):
"""
Explicitly refresh one or more index, making all operations performed
Expand All @@ -36,14 +36,22 @@ def refresh(self, index=None, params=None):
:arg index: A comma-separated list of index names; use `_all` or empty
string to perform the operation on all indices
:arg ignore_indices: When performed on multiple indices, allows to
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` string or
when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones, default u'none'
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
"""
_, data = self.transport.perform_request('POST', _make_path(index, '_refresh'),
params=params)
return data

@query_params('force', 'full', 'ignore_indices', 'refresh')
@query_params('force', 'full', 'allow_no_indices', 'expand_wildcards',
'ignore_indices', 'ignore_unavailable', 'refresh')
def flush(self, index=None, params=None):
"""
Explicitly flush one or more indices.
Expand All @@ -53,8 +61,15 @@ def flush(self, index=None, params=None):
string for all indices
:arg force: TODO: ?
:arg full: TODO: ?
:arg ignore_indices: When performed on multiple indices, allows to
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` string or
when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones (default: none)
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
:arg refresh: Refresh the index after performing the operation
"""
_, data = self.transport.perform_request('POST', _make_path(index, '_flush'),
Expand Down Expand Up @@ -134,7 +149,7 @@ def exists(self, index, params=None):
return False
return True

@query_params('ignore_indices')
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_indices', 'ignore_unavailable')
def exists_type(self, index, doc_type, params=None):
"""
Check if a type/types exists in an index/indices.
Expand All @@ -143,25 +158,39 @@ def exists_type(self, index, doc_type, params=None):
:arg index: A comma-separated list of index names; use `_all` to check
the types across all indices
:arg doc_type: A comma-separated list of document types to check
:arg ignore_indices: When performed on multiple indices, allows to
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` string or
when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones (default: none)
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
"""
try:
self.transport.perform_request('HEAD', _make_path(index, doc_type), params=params)
except NotFoundError:
return False
return True

@query_params('ignore_indices')
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_indices', 'ignore_unavailable')
def snapshot_index(self, index=None, params=None):
"""
Explicitly perform a snapshot through the gateway of one or more indices (backup them).
`<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-gateway-snapshot.html>`_
:arg index: A comma-separated list of index names; use `_all` or empty
string for all indices
:arg ignore_indices: When performed on multiple indices, allows to
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` string or
when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones (default: none)
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
"""
_, data = self.transport.perform_request('POST',
_make_path(index, '_gateway', 'snapshot'), params=params)
Expand Down Expand Up @@ -246,16 +275,23 @@ def put_alias(self, index, name, body=None, params=None):
params=params, body=body)
return data

@query_params('ignore_indices')
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_indices', 'ignore_unavailable')
def exists_alias(self, name, index=None, params=None):
"""
Return a boolean indicating whether given alias exists.
`<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html>`_
:arg name: A comma-separated list of alias names to return
:arg index: A comma-separated list of index names to filter aliases
:arg ignore_indices: When performed on multiple indices, allows to
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` string or
when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones (default: none)
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
"""
try:
self.transport.perform_request('HEAD', _make_path(index, '_alias', name),
Expand All @@ -264,16 +300,23 @@ def exists_alias(self, name, index=None, params=None):
return False
return True

@query_params('ignore_indices')
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_indices', 'ignore_unavailable')
def get_alias(self, name, index=None, params=None):
"""
Retrieve a specified alias.
`<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html>`_
:arg name: A comma-separated list of alias names to return
:arg index: A comma-separated list of index names to filter aliases
:arg ignore_indices: When performed on multiple indices, allows to
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` string or
when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones, default u'none'
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
"""
_, data = self.transport.perform_request('GET', _make_path(index, '_alias', name),
params=params)
Expand Down Expand Up @@ -444,16 +487,24 @@ def delete_warmer(self, index, doc_type=None, name=None, params=None):
params=params)
return data

@query_params('ignore_indices', 'operation_threading', 'recovery', 'snapshot')
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_indices',
'ignore_unavailable', 'operation_threading', 'recovery', 'snapshot')
def status(self, index=None, params=None):
"""
Get a comprehensive status information of one or more indices.
`<http://elasticsearch.org/guide/reference/api/admin-indices-_/>`_
:arg index: A comma-separated list of index names; use `_all` or empty
string to perform the operation on all indices
:arg ignore_indices: When performed on multiple indices, allows to
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` string or
when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones, default u'none'
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
:arg operation_threading: TODO: ?
:arg recovery: Return information about shard recovery
:arg snapshot: TODO: ?
Expand All @@ -464,8 +515,8 @@ def status(self, index=None, params=None):

@query_params('all', 'clear', 'completion', 'completion_fields', 'docs',
'fielddata', 'fielddata_fields', 'fields', 'filter_cache', 'flush', 'get', 'groups',
'id_cache', 'ignore_indices', 'indexing', 'merge', 'refresh', 'search',
'store', 'warmer')
'id_cache', 'allow_no_indices', 'expand_wildcards', 'ignore_indices',
'ignore_unavailable', 'indexing', 'merge', 'refresh', 'search', 'store', 'warmer')
def stats(self, index=None, metric_family=None, params=None):
"""
Retrieve statistics on different operations happening on an index.
Expand All @@ -490,8 +541,15 @@ def stats(self, index=None, metric_family=None, params=None):
:arg get: Return information about get operations
:arg groups: A comma-separated list of search groups for `search` statistics
:arg id_cache: Return information about ID cache
:arg ignore_indices: When performed on multiple indices, allows to
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` string or
when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones (default: none)
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
:arg indexing: Return information about indexing operations
:arg merge: Return information about merge operations
:arg refresh: Return information about refresh operations
Expand All @@ -504,23 +562,33 @@ def stats(self, index=None, metric_family=None, params=None):
params=params)
return data

@query_params('ignore_indices', 'operation_threading')
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_indices',
'ignore_unavailable', 'operation_threading')
def segments(self, index=None, params=None):
"""
Provide low level segments information that a Lucene index (shard level) is built with.
`<http://elasticsearch.org/guide/reference/api/admin-indices-segments/>`_
:arg index: A comma-separated list of index names; use `_all` or empty
string to perform the operation on all indices
:arg ignore_indices: When performed on multiple indices, allows to
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` string or
when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones, default u'none'
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
:arg operation_threading: TODO: ?
"""
_, data = self.transport.perform_request('GET', _make_path(index, '_segments'), params=params)
return data

@query_params('flush', 'ignore_indices', 'max_num_segments',
'only_expunge_deletes', 'operation_threading', 'refresh', 'wait_for_merge')
@query_params('flush', 'allow_no_indices', 'expand_wildcards',
'ignore_indices', 'ignore_unavailable', 'max_num_segments',
'only_expunge_deletes', 'operation_threading', 'refresh',
'wait_for_merge')
def optimize(self, index=None, params=None):
"""
Explicitly optimize one or more indices through an API.
Expand All @@ -530,8 +598,15 @@ def optimize(self, index=None, params=None):
string to perform the operation on all indices
:arg flush: Specify whether the index should be flushed after
performing the operation (default: true)
:arg ignore_indices: When performed on multiple indices, allows to
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` string or
when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones, default u'none'
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
:arg max_num_segments: The number of segments the index should be
merged into (default: dynamic)
:arg only_expunge_deletes: Specify whether the operation should only
Expand All @@ -545,7 +620,9 @@ def optimize(self, index=None, params=None):
_, data = self.transport.perform_request('POST', _make_path(index, '_optimize'), params=params)
return data

@query_params('explain', 'ignore_indices', 'operation_threading', 'q', 'source')
@query_params('explain', 'allow_no_indices', 'expand_wildcards',
'ignore_indices', 'ignore_unavailable', 'operation_threading', 'q',
'source')
def validate_query(self, index=None, doc_type=None, body=None, params=None):
"""
Validate a potentially expensive query without executing it.
Expand All @@ -557,8 +634,15 @@ def validate_query(self, index=None, doc_type=None, body=None, params=None):
operation; leave empty to perform the operation on all types
:arg body: The query definition
:arg explain: Return detailed information about the error
:arg ignore_indices: When performed on multiple indices, allows to
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` string or
when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones (default: none)
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
:arg operation_threading: TODO: ?
:arg q: Query in the Lucene query string syntax
:arg source: The URL-encoded query definition (instead of using the
Expand All @@ -568,9 +652,9 @@ def validate_query(self, index=None, doc_type=None, body=None, params=None):
params=params, body=body)
return data

@query_params('field_data', 'fielddata', 'fields', 'filter',
'filter_cache', 'filter_keys', 'id', 'id_cache', 'ignore_indices', 'index',
'recycler')
@query_params('field_data', 'fielddata', 'fields', 'filter', 'filter_cache',
'filter_keys', 'id', 'id_cache', 'allow_no_indices', 'expand_wildcards',
'ignore_indices', 'ignore_unavailable', 'index', 'recycler')
def clear_cache(self, index=None, params=None):
"""
Clear either all caches or specific cached associated with one ore more indices.
Expand All @@ -587,8 +671,15 @@ def clear_cache(self, index=None, params=None):
the `filter_cache` parameter (default: all)
:arg id: Clear ID caches for parent/child
:arg id_cache: Clear ID caches for parent/child
:arg ignore_indices: When performed on multiple indices, allows to
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all` string or
when no indices have been specified)
:arg expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:arg ignore_indices: When performed on multiple indices, allows to
ignore `missing` ones (default: none)
:arg ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
:arg index: A comma-separated list of index name to limit the operation
:arg recycler: Clear the recycler cache
"""
Expand Down

0 comments on commit b195705

Please sign in to comment.