Method: Elasticsearch::API::Indices::Actions#stats

Defined in:
lib/elasticsearch/api/actions/indices/stats.rb

#stats(arguments = {}) ⇒ Object

Get index statistics. For data streams, the API retrieves statistics for the stream’s backing indices. By default, the returned statistics are index-level with ‘primaries` and `total` aggregations. `primaries` are the values for only the primary shards. `total` are the accumulated values for both primary and replica shards. To get shard-level statistics, set the `level` parameter to `shards`. NOTE: When moving to another node, the shard-level statistics for a shard are cleared. Although the shard is no longer part of the node, that node retains any node-level statistics to which the shard contributed.

Parameters:

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

    a customizable set of options

Options Hash (arguments):

  • :metric (String, Array<String>)

    Limit the information returned the specific metrics.

  • :index (String, Array)

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

  • :completion_fields (String, Array<String>)

    Comma-separated list or wildcard expressions of fields to include in fielddata and suggest statistics.

  • :expand_wildcards (String, Array<String>)

    Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as ‘open,hidden`.

  • :fielddata_fields (String, Array<String>)

    Comma-separated list or wildcard expressions of fields to include in fielddata statistics.

  • :fields (String, Array<String>)

    Comma-separated list or wildcard expressions of fields to include in the statistics.

  • :forbid_closed_indices (Boolean)

    If true, statistics are not collected from closed indices. Server default: true.

  • :groups (String, Array<String>)

    Comma-separated list of search groups to include in the search statistics.

  • :include_segment_file_sizes (Boolean)

    If true, the call reports the aggregated disk usage of each one of the Lucene index files (only applies if segment stats are requested).

  • :include_unloaded_segments (Boolean)

    If true, the response includes information from segments that are not loaded into memory.

  • :level (String)

    Indicates whether statistics are aggregated at the cluster, indices, or shards level. Server default: indices.

  • :error_trace (Boolean)

    When set to ‘true` Elasticsearch will include the full stack trace of errors when they occur.

  • :filter_path (String, Array<String>)

    Comma-separated list of filters in dot notation which reduce the response returned by Elasticsearch.

  • :human (Boolean)

    When set to ‘true` will return statistics in a format suitable for humans. For example `“exists_time”: “1h”` for humans and `“exists_time_in_millis”: 3600000` for computers. When disabled the human readable values will be omitted. This makes sense for responses being consumed only by machines.

  • :pretty (Boolean)

    If set to ‘true` the returned JSON will be “pretty-formatted”. Only use this option for debugging only.

  • :headers (Hash)

    Custom HTTP headers

See Also:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/elasticsearch/api/actions/indices/stats.rb', line 62

def stats(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || 'indices.stats' }

  defined_params = [:metric, :index].each_with_object({}) do |variable, set_variables|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = nil

  _metric = arguments.delete(:metric)

  _index = arguments.delete(:index)

  method = Elasticsearch::API::HTTP_GET
  path   = if _index && _metric
             "#{Utils.listify(_index)}/_stats/#{Utils.listify(_metric)}"
           elsif _metric
             "_stats/#{Utils.listify(_metric)}"
           elsif _index
             "#{Utils.listify(_index)}/_stats"
           else
             '_stats'
           end
  params = Utils.process_params(arguments)

  Elasticsearch::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end