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/node_info.rb,
lib/elasticsearch/api/actions/cluster/node_stats.rb,
lib/elasticsearch/api/actions/cluster/get_settings.rb,
lib/elasticsearch/api/actions/cluster/put_settings.rb,
lib/elasticsearch/api/actions/cluster/node_shutdown.rb,
lib/elasticsearch/api/actions/cluster/node_hot_threads.rb

Instance Method Summary collapse

Instance Method Details

#get_settings(arguments = {}) ⇒ Object

Get the cluster settings (previously set with #put_settings)



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

def get_settings(arguments={})
  method = 'GET'
  path   = "_cluster/settings"
  params = {}
  body   = nil

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

#health(arguments = {}) ⇒ Object

Returns information about cluster “health”.

Examples:


client.cluster.health

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:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/elasticsearch/api/actions/cluster/health.rb', line 28

def health(arguments={})
  method = 'GET'
  path   = "_cluster/health"
  params = arguments.select do |k,v|
    [ :level,
      :local,
      :master_timeout,
      :timeout,
      :wait_for_active_shards,
      :wait_for_nodes,
      :wait_for_relocating_shards,
      :wait_for_status ].include?(k)
  end
  # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
  params = Hash[params] unless params.is_a?(Hash)
  body = nil

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

#node_hot_threads(arguments = {}) ⇒ String

Returns information about the hottest threads in the cluster or on a specific node as a String.

The information is returned as text, and allows you to understand what are currently the most taxing operations happening in the cluster, for debugging or monitoring purposes.

Examples:

Return 10 hottest threads


client.cluster.node_hot_threads threads: 10

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

  • :interval (Time)

    The interval for the second sampling of threads

  • :snapshots (Number)

    Number of samples of thread stacktrace (default: 10)

  • :threads (Number)

    Specify the number of threads to provide information for (default: 3)

  • :type (String)

    The type to sample (default: cpu) (options: cpu, wait, block)

Returns:

  • (String)

See Also:



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

def node_hot_threads(arguments={})
  method = 'GET'
  path   = "_cluster/nodes/#{arguments[:node_id]}/hot_threads".squeeze('/')
  params = arguments.select do |k,v|
    [ :interval,
      :snapshots,
      :threads,
      :type ].include?(k)
  end
  # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
  params = Hash[params] unless params.is_a?(Hash)
  body = nil

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

#node_info(arguments = {}) ⇒ Object

Returns information about nodes in the cluster (cluster settings, JVM version, etc).

Use the all option to return all available settings, or limit the information returned to a specific type (eg. http).

Use the node_id option to limit information to specific node(s).

Examples:

Return information about JVM


client.cluster.node_info jvm: true

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

  • :all (Boolean)

    Return all available information

  • :clear (Boolean)

    Reset the default settings

  • :http (Boolean)

    Return information about HTTP

  • :jvm (Boolean)

    Return information about the JVM

  • :network (Boolean)

    Return information about network

  • :os (Boolean)

    Return information about the operating system

  • :plugin (Boolean)

    Return information about plugins

  • :process (Boolean)

    Return information about the Elasticsearch process

  • :settings (Boolean)

    Return information about node settings

  • :thread_pool (Boolean)

    Return information about the thread pool

  • :transport (Boolean)

    Return information about transport

See Also:



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

def node_info(arguments={})
  method = 'GET'
  path   = Utils.__pathify( '_cluster/nodes', Utils.__listify(arguments[:node_id]) )
  params = arguments.select do |k,v|
    [ :all,
      :clear,
      :http,
      :jvm,
      :network,
      :os,
      :plugin,
      :process,
      :settings,
      :thread_pool,
      :transport ].include?(k)
  end
  # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
  params = Hash[params] unless params.is_a?(Hash)
  body = nil

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

#node_shutdown(arguments = {}) ⇒ Object

Shutdown one or all nodes

Examples:

Shut down node named Bloke


client.cluster.node_shutdown node_id: 'Bloke'

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 perform the operation on; use _local to shutdown the node you’re connected to, leave empty to shutdown all nodes

  • :delay (Time)

    Set the delay for the operation (default: 1s)

  • :exit (Boolean)

    Exit the JVM as well (default: true)

See Also:



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/elasticsearch/api/actions/cluster/node_shutdown.rb', line 20

def node_shutdown(arguments={})
  method = 'POST'
  path   = Utils.__pathify( '_cluster/nodes', Utils.__listify(arguments[:node_id]), '_shutdown' )
  params = arguments.select do |k,v|
    [ :delay,
      :exit ].include?(k)
  end
  # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
  params = Hash[params] unless params.is_a?(Hash)
  body   = nil

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

#node_stats(arguments = {}) ⇒ Object

Returns statistical information about nodes in the cluster.

Examples:

Return statistics about JVM


client.cluster.node_stats clear: true, jvm: true

Parameters:

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

    a customizable set of options

Options Hash (arguments):

  • :metric (List)

    Limit the information returned for indices family to a specific metric (options: docs, fielddata, filter_cache, flush, get, id_cache, indexing, merges, refresh, search, store, warmer)

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

  • :all (Boolean)

    Return all available information

  • :clear (Boolean)

    Reset the default level of detail

  • :fields (List)

    A comma-separated list of fields for fielddata metric (supports wildcards)

  • :fs (Boolean)

    Return information about the filesystem

  • :http (Boolean)

    Return information about HTTP

  • :indices (Boolean)

    Return information about indices

  • :jvm (Boolean)

    Return information about the JVM

  • :network (Boolean)

    Return information about network

  • :os (Boolean)

    Return information about the operating system

  • :process (Boolean)

    Return information about the Elasticsearch process

  • :thread_pool (Boolean)

    Return information about the thread pool

  • :transport (Boolean)

    Return information about transport

See Also:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/elasticsearch/api/actions/cluster/node_stats.rb', line 33

def node_stats(arguments={})
  method = 'GET'

  case
    # Field data metric for the `indices` metric family
    when arguments[:indices] && arguments[:metric] == 'fielddata'
      path   = Utils.__pathify( '_nodes', Utils.__listify(arguments[:node_id]), 'stats/indices/fielddata' )
      params = { :fields => Utils.__listify(arguments[:fields]) }

    # `indices` metric family incl. a metric
    when arguments[:indices] && arguments[:metric]
      path   = Utils.__pathify( '_nodes', Utils.__listify(arguments[:node_id]), 'stats/indices', arguments[:metric] )
      params = {}

    else
      path   = Utils.__pathify( '_nodes', Utils.__listify(arguments[:node_id]), 'stats' )

      params = arguments.select do |k,v|
        [ :all,
          :clear,
          :fields,
          :fs,
          :http,
          :indices,
          :jvm,
          :network,
          :os,
          :process,
          :thread_pool,
          :transport ].include?(k)
      end
      # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
      params = Hash[params] unless params.is_a?(Hash)

      params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
  end

  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
# File 'lib/elasticsearch/api/actions/cluster/put_settings.rb', line 17

def put_settings(arguments={})
  method = 'PUT'
  path   = "_cluster/settings"
  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

  • :filter_metadata (Boolean)

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

See Also:



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

def reroute(arguments={})
  method = 'POST'
  path   = "_cluster/reroute"
  params = arguments.select do |k,v|
    [ :dry_run,
      :filter_metadata ].include?(k)
  end
  # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
  params = Hash[params] unless params.is_a?(Hash)
  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):

  • :filter_blocks (Boolean)

    Do not return information about blocks

  • :filter_index_templates (Boolean)

    Do not return information about index templates

  • :filter_indices (List)

    Limit returned metadata information to specific indices

  • :filter_metadata (Boolean)

    Do not return information about indices metadata

  • :filter_nodes (Boolean)

    Do not return information about nodes

  • :filter_routing_table (Boolean)

    Do not return information about shard allocation (routing_table and routing_nodes)

  • :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
# File 'lib/elasticsearch/api/actions/cluster/state.rb', line 25

def state(arguments={})
  method = 'GET'
  path   = "_cluster/state"
  params = arguments.select do |k,v|
    [ :filter_blocks,
      :filter_index_templates,
      :filter_indices,
      :filter_metadata,
      :filter_nodes,
      :filter_routing_table,
      :local,
      :master_timeout ].include?(k)
  end
  # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
  params = Hash[params] unless params.is_a?(Hash)
  body = nil

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