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/health.rb,
lib/elasticsearch/api/actions/cluster/reroute.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

Instance Method Summary collapse

Instance Method Details

#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)

See Also:



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

def get_settings(arguments={})
  valid_params = [
    :flat_settings
  ]

  method = 'GET'
  path   = "_cluster/settings"
  params = Utils.__validate_and_extract_params arguments, valid_params
  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 (String)

    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 (Number)

    Wait until the specified number of shards is active

  • :wait_for_nodes (Number)

    Wait until the specified number of nodes is available

  • :wait_for_relocating_shards (Number)

    Wait until the specified number of relocating shards is finished

  • :wait_for_status (String)

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

See Also:



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

def health(arguments={})
  valid_params = [
    :level,
    :local,
    :master_timeout,
    :timeout,
    :wait_for_active_shards,
    :wait_for_nodes,
    :wait_for_relocating_shards,
    :wait_for_status ]

  method = 'GET'
  path   = "_cluster/health"

  params = Utils.__validate_and_extract_params arguments, valid_params
  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:



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

def pending_tasks(arguments={})
  valid_params = [
    :local,
    :master_timeout ]
  method = 'GET'
  path   = "/_cluster/pending_tasks"
  params = Utils.__validate_and_extract_params arguments, valid_params
  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).

See Also:



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

def put_settings(arguments={})
  valid_params = [ :flat_settings ]

  method = 'PUT'
  path   = "_cluster/settings"
  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = arguments[:body] || {}

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

#reroute(arguments = {}) ⇒ Object

Note:

If you want to explicitely 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 for why the commands can or cannot be executed

  • :filter_metadata (Boolean)

    Don’t return cluster state metadata (default: false)

See Also:



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

def reroute(arguments={})
  valid_params = [ :dry_run, :explain, :filter_metadata ]

  method = 'POST'
  path   = "_cluster/reroute"

  params = Utils.__validate_and_extract_params arguments, valid_params
  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 omit to perform the operation on all indices

  • :metric (List)

    Limit the information returned to the specified metrics (options: _all, blocks, index_templates, metadata, nodes, routing_table,

    master_node, version)
    
  • :index_templates (List)

    A comma separated list to return specific index templates when returning metadata

  • :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:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/elasticsearch/api/actions/cluster/state.rb', line 25

def state(arguments={})
  arguments = arguments.clone
  index     = arguments.delete(:index)
  metric    = arguments.delete(:metric)

  valid_params = [
    :metric,
    :index_templates,
    :local,
    :master_timeout,
    :flat_settings ]

  method = 'GET'
  path   = "_cluster/state"

  path   = Utils.__pathify '_cluster/state',
                           Utils.__listify(metric),
                           Utils.__listify(index)

  params = Utils.__validate_and_extract_params arguments, valid_params

  [: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