pyes.managers

class pyes.managers.Cluster(conn)
health(indices=None, level='cluster', wait_for_status=None, wait_for_relocating_shards=None, timeout=30)

Check the current cluster health. Request Parameters

The cluster health API accepts the following request parameters:

Parameters:
  • level – Can be one of cluster, indices or shards. Controls the details level of the health information returned. Defaults to cluster.
  • wait_for_status – One of green, yellow or red. Will wait (until the timeout provided) until the status of the cluster changes to the one provided. By default, will not wait for any status.
  • wait_for_relocating_shards – A number controlling to how many relocating shards to wait for. Usually will be 0 to indicate to wait till all relocation have happened. Defaults to not to wait.
  • timeout – A time based parameter controlling how long to wait if one of the wait_for_XXX are provided. Defaults to 30s.
info()

The cluster nodes info API allows to retrieve one or more (or all) of the cluster nodes information.

node_field_stats(nodes=None)

Retrieve field stats per node(s) or cluster wide nodes info API allows to retrieve one or more (or all) the cluster nodes info about field data memory usage

node_stats(nodes=None)

The cluster nodes info API allows to retrieve one or more (or all) of the cluster nodes information.

nodes_info(nodes=None)

The cluster nodes info API allows to retrieve one or more (or all) of the cluster nodes information.

shutdown(all_nodes=False, master=False, local=False, nodes=[], delay=None)
state(filter_nodes=None, filter_routing_table=None, filter_metadata=None, filter_blocks=None, filter_indices=None)

Retrieve the cluster state.

Parameters:
  • filter_nodes – set to true to filter out the nodes part of the response.
  • filter_routing_table – set to true to filter out the routing_table part of the response.
  • filter_metadata – set to true to filter out the metadata part of the response.
  • filter_blocks – set to true to filter out the blocks part of the response.
  • filter_indices – when not filtering metadata, a comma separated list of indices to include in the response.
class pyes.managers.Indices(conn)
add_alias(alias, indices, **kwargs)

Add an alias to point to a set of indices. (See Admin Indices Aliases)

Parameters:
  • alias – the name of an alias
  • indices – a list of indices
alias_params = ['filter', 'routing', 'search_routing', 'index_routing']
aliases(indices=None)

Retrieve the aliases of one or more indices. ( See Admin Indices Aliases)

Parameters:indices – an index or a list of indices
analyze(text, index=None, analyzer=None, tokenizer=None, filters=None, field=None)

Performs the analysis process on a text and return the tokens breakdown of the text

(See Admin Indices Optimize)

change_aliases(commands)

Change the aliases stored. (See Admin Indices Aliases)

Parameters:commands – is a list of 3-tuples; (command, index, alias), where command is one of “add” or “remove”, and index and alias are the index and alias to add or remove.
close_index(index)

Close an index. (See Admin Indices Open Close)

Parameters:index – the name of the index
create_index(index, settings=None)

Creates an index with optional settings. Admin Indices Create Index

Parameters:
  • index – the name of the index
  • settings – a settings object or a dict containing settings
create_index_if_missing(index, settings=None)

Creates an index if it doesn’t already exist.

If supplied, settings must be a dictionary.

Parameters:
  • index – the name of the index
  • settings – a settings object or a dict containing settings
delete_alias(alias, indices)

Delete an alias. (See Admin Indices Aliases)

The specified index or indices are deleted from the alias, if they are in it to start with. This won’t report an error even if the indices aren’t present in the alias.

Parameters:
  • alias – the name of an alias
  • indices – a list of indices
delete_index(index)

Deletes an index. Admin Indices Delete Index

Parameters:index – the name of the index
delete_index_if_exists(index)

Deletes an index if it exists.

Parameters:index – the name of the index
delete_mapping(index, doc_type)

Delete a typed JSON document type from a specific index. (See Admin Indices Delete Mapping)

exists_index(index)

Check if an index exists. (See Admin Indices Indices Exists)

Parameters:index – the name of the index
field_stats(indices='')

Retrieve the field data stats for one or more indices (See :ref:’es-guide-reference-api-admin-cluster-nodes-stats’)

Parameters:indices – an index or a list of indices
flush(indices=None, refresh=None)

Flushes one or more indices (clear memory) If a bulk is full, it sends it.

(See Admin Indices Flush)

Parameters:
  • indices – an index or a list of indices
  • refresh – set the refresh parameter
gateway_snapshot(indices=None)

Gateway snapshot one or more indices (See Admin Indices Gateway Snapshot)

Parameters:indices – a list of indices or None for default configured.
get_alias(alias)

Get the index or indices pointed to by a given alias. (See Admin Indices Aliases)

Parameters:alias – the name of an alias

:return returns a list of index names. :raise IndexMissingException if the alias does not exist.

get_closed_indices()

Get all closed indices.

get_indices(include_aliases=False)

Get a dict holding an entry for each index which exists.

If include_alises is True, the dict will also contain entries for aliases.

The key for each entry in the dict is the index or alias name. The value is a dict holding the following properties:

  • num_docs: Number of documents in the index or alias.
  • alias_for: Only present for an alias: holds a list of indices which this is an alias for.
get_mapping(doc_type=None, indices=None, raw=False)

Register specific mapping definition for a specific type against one or more indices. (See Admin Indices Get Mapping)

get_settings(index=None)

Returns the current settings for an index. (See Admin Indices Get Settings)

open_index(index)

Open an index. (See Admin Indices Open Close)

Parameters:index – the name of the index
optimize(indices=None, wait_for_merge=False, max_num_segments=None, only_expunge_deletes=False, refresh=True, flush=True)

Optimize one or more indices. (See Admin Indices Optimize)

Parameters:
  • indices – the list of indices to optimise. If not supplied, all default_indices are optimised.
  • wait_for_merge – If True, the operation will not return until the merge has been completed. Defaults to False.
  • max_num_segments – The number of segments to optimize to. To fully optimize the index, set it to 1. Defaults to half the number configured by the merge policy (which in turn defaults to 10).
  • only_expunge_deletes – Should the optimize process only expunge segments with deletes in it. In Lucene, a document is not deleted from a segment, just marked as deleted. During a merge process of segments, a new segment is created that does have those deletes. This flag allow to only merge segments that have deletes. Defaults to false.
  • refresh – Should a refresh be performed after the optimize. Defaults to true.
  • flush – Should a flush be performed after the optimize. Defaults to true.
put_mapping(doc_type=None, mapping=None, indices=None, ignore_conflicts=None)

Register specific mapping definition for a specific type against one or more indices. (See Admin Indices Put Mapping)

refresh(indices=None, timesleep=None, timeout=0)

Refresh one or more indices If a bulk is full, it sends it. (See Admin Indices Refresh)

Parameters:
  • indices – an index or a list of indices
  • timesleep – seconds to wait
  • timeout – seconds to wait before timing out when waiting for the cluster’s health.
set_alias(alias, indices, **kwargs)

Set an alias. (See Admin Indices Aliases)

This handles removing the old list of indices pointed to by the alias.

Warning: there is a race condition in the implementation of this function - if another client modifies the indices which this alias points to during this call, the old value of the alias may not be correctly set.

Parameters:
  • alias – the name of an alias
  • indices – a list of indices
stats(indices=None)

Retrieve the statistic of one or more indices (See Admin Indices Stats)

Parameters:indices – an index or a list of indices
status(indices=None)

Retrieve the status of one or more indices (See Admin Indices Status)

Parameters:indices – an index or a list of indices
update_settings(index, newvalues)

Update Settings of an index. (See Admin Indices Update Settings)