Module: Elasticsearch::API::Cluster::Actions

Included in:
ClusterClient
Defined in:
lib/elasticsearch/api/namespace/cluster.rb,
lib/elasticsearch/api/actions/cluster/state.rb,
lib/elasticsearch/api/actions/cluster/stats.rb,
lib/elasticsearch/api/actions/cluster/health.rb,
lib/elasticsearch/api/actions/cluster/reroute.rb,
lib/elasticsearch/api/actions/cluster/remote_info.rb,
lib/elasticsearch/api/actions/cluster/get_settings.rb,
lib/elasticsearch/api/actions/cluster/put_settings.rb,
lib/elasticsearch/api/actions/cluster/pending_tasks.rb,
lib/elasticsearch/api/actions/cluster/params_registry.rb,
lib/elasticsearch/api/actions/cluster/allocation_explain.rb

Defined Under Namespace

Modules: ParamsRegistry

Instance Method Summary collapse

Instance Method Details

#allocation_explain(arguments = {}) ⇒ Object

Return the information about why a shard is or isn’t allocated

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :body (Hash)

    The index, shard, and primary flag to explain. Empty means ‘explain the first unassigned shard’

  • :include_yes_decisions (Boolean)

    Return ‘YES’ decisions in explanation (default: false)

  • :include_disk_info (Boolean)

    Return information about disk usage and shard sizes (default: false)

See Also:



14
15
16
17
18
19
20
21
# File 'lib/elasticsearch/api/actions/cluster/allocation_explain.rb', line 14

def allocation_explain(arguments={})
  method = 'GET'
  path   = "_cluster/allocation/explain"
  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
  body   = arguments[:body]

  perform_request(method, path, params, body).body
end

#get_settings(arguments = {}) ⇒ Object

Get the cluster settings (previously set with #put_settings)

Examples:

Get cluster settings


client.cluster.get_settings

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :flat_settings (Boolean)

    Return settings in flat format (default: false)

  • :master_timeout (Time)

    Explicit operation timeout for connection to master node

  • :timeout (Time)

    Explicit operation timeout

  • :include_defaults (Boolean)

    Whether to return all default clusters setting.

See Also:



19
20
21
22
23
24
25
26
# File 'lib/elasticsearch/api/actions/cluster/get_settings.rb', line 19

def get_settings(arguments={})
  method = HTTP_GET
  path   = "_cluster/settings"
  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
  body   = nil

  perform_request(method, path, params, body).body
end

#health(arguments = {}) ⇒ Object

Returns information about cluster “health”.

Examples:

Get the cluster health information


client.cluster.health

Block the request until the cluster is in the “yellow” state


client.cluster.health wait_for_status: 'yellow'

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (List)

    Limit the information returned to a specific index

  • :level (String)

    Specify the level of detail for returned information (options: cluster, indices, shards)

  • :local (Boolean)

    Return local information, do not retrieve the state from master node (default: false)

  • :master_timeout (Time)

    Explicit operation timeout for connection to master node

  • :timeout (Time)

    Explicit operation timeout

  • :wait_for_active_shards (String)

    Wait until the specified number of shards is active

  • :wait_for_nodes (String)

    Wait until the specified number of nodes is available

  • :wait_for_events (String)

    Wait until all currently queued events with the given priority are processed (options: immediate, urgent, high, normal, low, languid)

  • :wait_for_no_relocating_shards (Boolean)

    Whether to wait until there are no relocating shards in the cluster

  • :wait_for_no_initializing_shards (Boolean)

    Whether to wait until there are no initializing shards in the cluster

  • :wait_for_status (String)

    Wait until cluster is in a specific state (options: green, yellow, red)

See Also:



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/elasticsearch/api/actions/cluster/health.rb', line 30

def health(arguments={})
  arguments = arguments.clone
  index     = arguments.delete(:index)
  method = HTTP_GET
  path   = Utils.__pathify "_cluster/health", Utils.__listify(index)

  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
  body = nil

  perform_request(method, path, params, body).body
end

#pending_tasks(arguments = {}) ⇒ Object

Returns a list of any cluster-level changes (e.g. create index, update mapping, allocate or fail shard) which have not yet been executed and are queued up.

Examples:

Get a list of currently queued up tasks in the cluster


client.cluster.pending_tasks

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :local (Boolean)

    Return local information, do not retrieve the state from master node (default: false)

  • :master_timeout (Time)

    Specify timeout for connection to master

See Also:



18
19
20
21
22
23
24
25
# File 'lib/elasticsearch/api/actions/cluster/pending_tasks.rb', line 18

def pending_tasks(arguments={})
  method = HTTP_GET
  path   = "_cluster/pending_tasks"
  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
  body   = nil

  perform_request(method, path, params, body).body
end

#put_settings(arguments = {}) ⇒ Object

Update cluster settings.

Examples:

Disable shard allocation in the cluster until restart


client.cluster.put_settings body: { transient: { 'cluster.routing.allocation.disable_allocation' => true } }

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :body (Hash)

    The settings to be updated. Can be either ‘transient` or `persistent` (survives cluster restart). (Required)

  • :flat_settings (Boolean)

    Return settings in flat format (default: false)

  • :master_timeout (Time)

    Explicit operation timeout for connection to master node

  • :timeout (Time)

    Explicit operation timeout

See Also:



19
20
21
22
23
24
25
26
# File 'lib/elasticsearch/api/actions/cluster/put_settings.rb', line 19

def put_settings(arguments={})
  method = HTTP_PUT
  path   = "_cluster/settings"
  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
  body   = arguments[:body] || {}

  perform_request(method, path, params, body).body
end

#remote_info(arguments = {}) ⇒ Object

Returns the configured remote cluster information



11
12
13
14
15
16
17
18
# File 'lib/elasticsearch/api/actions/cluster/remote_info.rb', line 11

def remote_info(arguments={})
  method = Elasticsearch::API::HTTP_GET
  path   = "_remote/info"
  params = {}
  body   = nil

  perform_request(method, path, params, body).body
end

#reroute(arguments = {}) ⇒ Object

Note:

If you want to explicitly set the shard allocation to a certain node, you might want to look at the ‘allocation.*` cluster settings.

Perform manual shard allocation in the cluster.

Pass the operations you want to perform in the ‘:body` option. Use the `dry_run` option to evaluate the result of operations without actually performing them.

Examples:

Move shard ‘0` of index `myindex` from node named Node1 to node named Node2


client.cluster.reroute body: {
  commands: [
    { move: { index: 'myindex', shard: 0, from_node: 'Node1', to_node: 'Node2' } }
  ]
}

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :body (Hash)

    The definition of ‘commands` to perform (`move`, `cancel`, `allocate`)

  • :dry_run (Boolean)

    Simulate the operation only and return the resulting state

  • :explain (Boolean)

    Return an explanation of why the commands can or cannot be executed

  • :retry_failed (Boolean)

    Retries allocation of shards that are blocked due to too many subsequent allocation failures

  • :metric (List)

    Limit the information returned to the specified metrics. Defaults to all but metadata (options: _all, blocks, metadata, nodes, routing_table, master_node, version)

  • :master_timeout (Time)

    Explicit operation timeout for connection to master node

  • :timeout (Time)

    Explicit operation timeout

See Also:



34
35
36
37
38
39
40
41
42
# File 'lib/elasticsearch/api/actions/cluster/reroute.rb', line 34

def reroute(arguments={})
  method = HTTP_POST
  path   = "_cluster/reroute"

  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
  body   = arguments[:body] || {}

  perform_request(method, path, params, body).body
end

#state(arguments = {}) ⇒ Object

Get information about the cluster state (indices settings, allocations, etc)

Examples:


client.cluster.state

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names; use ‘_all` or empty string to perform the operation on all indices

  • :metric (List)

    Limit the information returned to the specified metrics (options: _all,blocks,metadata,nodes,routing_table,routing_nodes,master_node,version)

  • :local (Boolean)

    Return local information, do not retrieve the state from master node (default: false)

  • :master_timeout (Time)

    Specify timeout for connection to master

  • :flat_settings (Boolean)

    Return settings in flat format (default: false)

  • :wait_for_metadata_version (Number)

    Wait for the metadata version to be equal or greater than the specified metadata version

  • :wait_for_timeout (Time)

    The maximum time to wait for wait_for_metadata_version before timing out

  • :ignore_unavailable (Boolean)

    Whether specified concrete indices should be ignored when unavailable (missing or closed)

  • :allow_no_indices (Boolean)

    Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes ‘_all` string or when no indices have been specified)

  • :expand_wildcards (String)

    Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed, none, all)

See Also:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/elasticsearch/api/actions/cluster/state.rb', line 33

def state(arguments={})
  arguments = arguments.clone
  index     = arguments.delete(:index)
  metric    = arguments.delete(:metric)
  method = HTTP_GET
  path   = Utils.__pathify '_cluster/state',
                           Utils.__listify(metric),
                           Utils.__listify(index)

  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)

  [:index_templates].each do |key|
    params[key] = Utils.__listify(params[key]) if params[key]
  end

  body = nil

  perform_request(method, path, params, body).body
end

#stats(arguments = {}) ⇒ Object

Returns statistical information about the cluster

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :node_id (List)

    A comma-separated list of node IDs or names to limit the returned information; use ‘_local` to return information from the node you’re connecting to, leave empty to get information from all nodes

  • :flat_settings (Boolean)

    Return settings in flat format (default: false)

  • :timeout (Time)

    Explicit operation timeout

See Also:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/elasticsearch/api/actions/cluster/stats.rb', line 17

def stats(arguments={})
  method = 'GET'
  node_id = arguments.delete(:node_id)

  if node_id
    path = Utils.__pathify("_cluster/stats/nodes", node_id)
  else
    path = "_cluster/stats"
  end
  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
  body   = nil

  perform_request(method, path, params, body).body
end