Module: Elasticsearch::API::Indices::Actions

Included in:
IndicesClient
Defined in:
lib/elasticsearch/api/namespace/indices.rb,
lib/elasticsearch/api/actions/indices/open.rb,
lib/elasticsearch/api/actions/indices/close.rb,
lib/elasticsearch/api/actions/indices/flush.rb,
lib/elasticsearch/api/actions/indices/stats.rb,
lib/elasticsearch/api/actions/indices/create.rb,
lib/elasticsearch/api/actions/indices/delete.rb,
lib/elasticsearch/api/actions/indices/exists.rb,
lib/elasticsearch/api/actions/indices/status.rb,
lib/elasticsearch/api/actions/indices/analyze.rb,
lib/elasticsearch/api/actions/indices/refresh.rb,
lib/elasticsearch/api/actions/indices/optimize.rb,
lib/elasticsearch/api/actions/indices/segments.rb,
lib/elasticsearch/api/actions/indices/get_alias.rb,
lib/elasticsearch/api/actions/indices/put_alias.rb,
lib/elasticsearch/api/actions/indices/get_warmer.rb,
lib/elasticsearch/api/actions/indices/put_warmer.rb,
lib/elasticsearch/api/actions/indices/clear_cache.rb,
lib/elasticsearch/api/actions/indices/exists_type.rb,
lib/elasticsearch/api/actions/indices/get_aliases.rb,
lib/elasticsearch/api/actions/indices/get_mapping.rb,
lib/elasticsearch/api/actions/indices/put_mapping.rb,
lib/elasticsearch/api/actions/indices/delete_alias.rb,
lib/elasticsearch/api/actions/indices/exists_alias.rb,
lib/elasticsearch/api/actions/indices/get_settings.rb,
lib/elasticsearch/api/actions/indices/get_template.rb,
lib/elasticsearch/api/actions/indices/put_settings.rb,
lib/elasticsearch/api/actions/indices/put_template.rb,
lib/elasticsearch/api/actions/indices/delete_warmer.rb,
lib/elasticsearch/api/actions/indices/delete_mapping.rb,
lib/elasticsearch/api/actions/indices/snapshot_index.rb,
lib/elasticsearch/api/actions/indices/update_aliases.rb,
lib/elasticsearch/api/actions/indices/validate_query.rb,
lib/elasticsearch/api/actions/indices/delete_template.rb,
lib/elasticsearch/api/actions/indices/get_field_mapping.rb

Instance Method Summary collapse

Instance Method Details

#analyze(arguments = {}) ⇒ Object

Return the result of the analysis process (tokens)

Allows to “test-drive” the Elasticsearch analysis process by performing the analysis on the same text with different analyzers. An ad-hoc analysis chain can be built from specific tokenizer and filters.

Examples:

Analyze text “Quick Brown Jumping Fox” with the snowball analyzer


client.indices.analyze text: 'The Quick Brown Jumping Fox', analyzer: 'snowball'

Analyze text “Quick Brown Jumping Fox” with a custom tokenizer and filter chain


client.indices.analyze text: 'The Quick Brown Jumping Fox',
                       tokenizer: 'whitespace',
                       filters: ['lowercase','stop']

Options Hash (arguments):

  • :index (String)

    The name of the index to scope the operation

  • :body (Hash)

    The text on which the analysis should be performed

  • :analyzer (String)

    The name of the analyzer to use

  • :field (String)

    Use the analyzer configured for this field (instead of passing the analyzer name)

  • :filters (List)

    A comma-separated list of filters to use for the analysis

  • :index (String)

    The name of the index to scope the operation

  • :prefer_local (Boolean)

    With true, specify that a local shard should be used if available, with false, use a random shard (default: true)

  • :text (String)

    The text on which the analysis should be performed (when request body is not used)

  • :tokenizer (String)

    The name of the tokenizer to use for the analysis

  • :format (String)

    Format of the output (options: detailed, text)

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/elasticsearch/api/actions/indices/analyze.rb', line 38

def analyze(arguments={})
  valid_params = [
    :analyzer,
    :field,
    :filters,
    :index,
    :prefer_local,
    :text,
    :tokenizer,
    :format ]

  method = 'GET'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_analyze'

  params = Utils.__validate_and_extract_params arguments, valid_params
  params[:filters] = Utils.__listify(params[:filters]) if params[:filters]

  body   = arguments[:body]

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

#clear_cache(arguments = {}) ⇒ Object

Clear caches and other auxiliary data structures.

Can be performed against a specific index, or against all indices.

By default, all caches and data structures will be cleared. Pass a specific cache or structure name to clear just a single one.

Examples:

Clear all caches and data structures


client.indices.clear_cache

Clear the field data structure only


client.indices.clear_cache field_data: true

Clear only specific field in the field data structure


client.indices.clear_cache field_data: true, fields: 'created_at', filter_cache: false, id_cache: false

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index name to limit the operation

  • :field_data (Boolean)

    Clear field data

  • :fielddata (Boolean)

    Clear field data

  • :fields (List)

    A comma-separated list of fields to clear when using the field_data parameter(default: all)

  • :filter (Boolean)

    Clear filter caches

  • :filter_cache (Boolean)

    Clear filter caches

  • :filter_keys (Boolean)

    A comma-separated list of keys to clear when using the filter_cache parameter (default: all)

  • :id (Boolean)

    Clear ID caches for parent/child

  • :id_cache (Boolean)

    Clear ID caches for parent/child

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore missing ones (options: none, missing)

  • :index (List)

    A comma-separated list of index name to limit the operation

  • :recycler (Boolean)

    Clear the recycler cache

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/elasticsearch/api/actions/indices/clear_cache.rb', line 43

def clear_cache(arguments={})
  valid_params = [
    :field_data,
    :fielddata,
    :fields,
    :filter,
    :filter_cache,
    :filter_keys,
    :id,
    :id_cache,
    :ignore_indices,
    :recycler ]

  method = 'POST'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_cache/clear'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

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

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

#close(arguments = {}) ⇒ Object

Close an index (keep the data on disk, but deny operations with the index).

A closed index can be opened again with the #close API.

Examples:

Close index named myindex


client.indices.close index: 'myindex'

Options Hash (arguments):

  • :index (String)

    The name of the index (Required)

  • :timeout (Time)

    Explicit operation timeout

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



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

def close(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  valid_params = [ :timeout ]

  method = 'POST'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_close'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

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

#create(arguments = {}) ⇒ Object

Create an index.

Pass the index settings and mappings in the :body attribute.

Examples:

Create an index with specific settings, custom analyzers and mappings


client.indices.create index: 'test',
                      body: {
                        settings: {
                          index: {
                            number_of_shards: 1,
                            number_of_replicas: 0,
                            'routing.allocation.include.name' => 'node-1'
                          },
                          analysis: {
                            filter: {
                              ngram: {
                                type: 'nGram',
                                min_gram: 3,
                                max_gram: 25
                              }
                            },
                            analyzer: {
                              ngram: {
                                tokenizer: 'whitespace',
                                filter: ['lowercase', 'stop', 'ngram'],
                                type: 'custom'
                              },
                              ngram_search: {
                                tokenizer: 'whitespace',
                                filter: ['lowercase', 'stop'],
                                type: 'custom'
                              }
                            }
                          }
                        },
                        mappings: {
                          document: {
                            properties: {
                              title: {
                                type: 'multi_field',
                                fields: {
                                    title:  { type: 'string', analyzer: 'snowball' },
                                    exact:  { type: 'string', analyzer: 'keyword' },
                                    ngram:  { type: 'string',
                                              index_analyzer: 'ngram',
                                              search_analyzer: 'ngram_search'
                                    }
                                }
                              }
                            }
                          }
                        }
                      }

Options Hash (arguments):

  • :index (String)

    The name of the index (Required)

  • :body (Hash)

    Optional configuration for the index (settings and mappings)

  • :timeout (Time)

    Explicit operation timeout

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/elasticsearch/api/actions/indices/create.rb', line 67

def create(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  valid_params = [ :timeout ]

  method = 'PUT'
  path   = Utils.__pathify Utils.__escape(arguments[:index])

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = arguments[:body]

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

#delete(arguments = {}) ⇒ Object

Delete an index, list of indices, or all indices in the cluster.

Examples:

Delete an index


client.indices.delete index: 'foo'

Delete a list of indices


client.indices.delete index: ['foo', 'bar']
client.indices.delete index: 'foo,bar'

Delete a list of indices matching wildcard expression


client.indices.delete index: 'foo*'

Delete all indices


client.indices.delete
client.indices.delete index: '_all'

Options Hash (arguments):

  • :index (List)

    A comma-separated list of indices to delete; use _all or leave empty to delete all indices

  • :timeout (Time)

    Explicit operation timeout

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/elasticsearch/api/actions/indices/delete.rb', line 33

def delete(arguments={})
  valid_params = [ :timeout ]

  method = 'DELETE'
  path   = Utils.__pathify Utils.__listify(arguments[:index])

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

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

#delete_alias(arguments = {}) ⇒ Object

Delete a single index alias.

See the #update_aliases for performing operations with index aliases in bulk.

Examples:

Delete an alias


client.indices.delete_alias index: 'foo', name: 'bar'

Options Hash (arguments):

  • :index (String)

    The name of the index with an alias (Required)

  • :name (String)

    The name of the alias to be deleted (Required)

  • :timeout (Time)

    Explicit timestamp for the document

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



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

def delete_alias(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'name' missing"  unless arguments[:name]
  valid_params = [ :timeout ]

  method = 'DELETE'
  path   = Utils.__pathify Utils.__escape(arguments[:index]), '_alias', Utils.__escape(arguments[:name])

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

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

#delete_mapping(arguments = {}) ⇒ Object

Delete all documents and mapping for a specific document type.

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names; use _all for all indices (Required)

  • :type (String)

    The name of the document type to delete (Required)

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



13
14
15
16
17
18
19
20
21
22
# File 'lib/elasticsearch/api/actions/indices/delete_mapping.rb', line 13

def delete_mapping(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'type' missing"  unless arguments[:type]
  method = 'DELETE'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), Utils.__escape(arguments[:type])
  params = {}
  body   = nil

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

#delete_template(arguments = {}) ⇒ Object

Delete an index template.

Examples:

Delete a template named mytemplate


client.indices.delete_template name: 'mytemplate'

Options Hash (arguments):

  • :name (String)

    The name of the template (Required)

  • :timeout (Time)

    Explicit operation timeout

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/elasticsearch/api/actions/indices/delete_template.rb', line 17

def delete_template(arguments={})
  raise ArgumentError, "Required argument 'name' missing" unless arguments[:name]
  valid_params = [ :timeout ]

  method = 'DELETE'
  path   = Utils.__pathify '_template', Utils.__escape(arguments[:name])

  params = Utils.__validate_and_extract_params arguments, valid_params
  body = nil

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

rescue Exception => e
  # NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability
  if arguments[:ignore] == 404 && e.class.to_s =~ /NotFound/; false
  else raise(e)
  end
end

#delete_warmer(arguments = {}) ⇒ Object

Delete one or more warmers for a list of indices.

Examples:

Delete a warmer named mywarmer for index named myindex


client.indices.delete_warmer index: 'myindex', name: 'mywarmer'

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names to register warmer for; use _all or empty string to perform the operation on all indices (Required)

  • :name (String)

    The name of the warmer (supports wildcards); leave empty to delete all warmers

  • :type (List)

    A comma-separated list of document types to register warmer for; use _all or empty string to perform the operation on all types

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



20
21
22
23
24
25
26
27
28
# File 'lib/elasticsearch/api/actions/indices/delete_warmer.rb', line 20

def delete_warmer(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  method = 'DELETE'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_warmer', Utils.__listify(arguments[:name])
  params = {}
  body = nil

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

#exists(arguments = {}) ⇒ true, false

Return true if the index (or all indices in a list) exists, false otherwise.

Examples:

Check whether index named myindex exists


client.indices.exists index: 'myindex'

Options Hash (arguments):

  • :index (List)

    A comma-separated list of indices to check (Required)

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options

Returns:



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

def exists(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  method = 'HEAD'
  path   = Utils.__listify(arguments[:index])
  params = {}
  body   = nil

  perform_request(method, path, params, body).status == 200 ? true : false
rescue Exception => e
  if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
    false
  else
    raise e
  end
end

#exists_alias(arguments = {}) ⇒ Object

Return true if the specified alias exists, false otherwise.

Examples:

Check whether index alias named myalias exists


client.indices.exists_alias name: 'myalias'

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names to filter aliases

  • :name (List)

    A comma-separated list of alias names to return (Required)

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore missing ones (options: none, missing)

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/elasticsearch/api/actions/indices/exists_alias.rb', line 19

def exists_alias(arguments={})
  raise ArgumentError, "Required argument 'name' missing" unless arguments[:name]
  valid_params = [ :ignore_indices ]

  method = 'HEAD'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_alias', Utils.__escape(arguments[:name])

  params = Utils.__validate_and_extract_params arguments, valid_params
  body = nil

  perform_request(method, path, params, body).status == 200 ? true : false
rescue Exception => e
  if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
    false
  else
    raise e
  end
end

#exists_type(arguments = {}) ⇒ Object

Return true if the specified type exists, false otherwise.

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names; use _all to check the types across all indices (Required)

  • :type (List)

    A comma-separated list of document types to check (Required)

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore missing ones (options: none, missing)

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/elasticsearch/api/actions/indices/exists_type.rb', line 16

def exists_type(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
  valid_params = [ :ignore_indices ]

  method = 'HEAD'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), Utils.__escape(arguments[:type])

  params = Utils.__validate_and_extract_params arguments, valid_params
  body = nil

  perform_request(method, path, params, body).status == 200 ? true : false
rescue Exception => e
  if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
    false
  else
    raise e
  end
end

#flush(arguments = {}) ⇒ Object

Note:

The flush operation is handled automatically by Elasticsearch, you don’t need to perform it manually.

“Flush” the index or indices.

The “flush” operation clears the transaction log and memory and writes data to disk. It corresponds to a Lucene “commit” operation.

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names; use _all or empty string for all indices

  • :force (Boolean)

    TODO: ?

  • :full (Boolean)

    TODO: ?

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore missing ones (options: none, missing)

  • :refresh (Boolean)

    Refresh the index after performing the operation

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/elasticsearch/api/actions/indices/flush.rb', line 22

def flush(arguments={})
  valid_params = [
    :force,
    :full,
    :ignore_indices,
    :refresh ]

  method = 'POST'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_flush'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body = nil

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

#get_alias(arguments = {}) ⇒ Object

Get information about a specific alias.

Examples:

Return all indices an alias points to


client.indices.get_alias name: '2013'

Return all indices matching a wildcard pattern an alias points to


client.indices.get_alias index: 'log*', name: '2013'

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names to filter aliases

  • :name (List)

    A comma-separated list of alias names to return (Required)

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore missing ones (options: none, missing)

  • :index (List)

    A comma-separated list of index names to filter aliases

  • :name (List)

    A comma-separated list of alias names to return

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/elasticsearch/api/actions/indices/get_alias.rb', line 25

def get_alias(arguments={})
  raise ArgumentError, "Required argument 'name' missing" unless arguments[:name]
  valid_params = [ :ignore_indices ]

  method = 'GET'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_alias', Utils.__escape(arguments[:name])

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

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

#get_aliases(arguments = {}) ⇒ Object

Get a list of all aliases, or aliases for a specific index.

Examples:

Get a list of all aliases


client.indices.get_aliases

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names to filter aliases

  • :timeout (Time)

    Explicit timestamp for the document

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



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

def get_aliases(arguments={})
  valid_params = [ :timeout ]

  method = 'GET'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_aliases'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

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

#get_field_mapping(arguments = {}) ⇒ Object

Return the mapping definition for specific field (or fields)

Examples:

Get mapping for a specific field across all indices


client.indices.get_field_mapping field: 'foo'

Get mapping for a specific field in an index


client.indices.get_field_mapping index: 'foo', field: 'bar'

Get mappings for multiple fields in an index


client.indices.get_field_mapping index: 'foo', field: ['bar', 'bam']

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names

  • :type (List)

    A comma-separated list of document types

  • :field (List)

    A comma-separated list of fields (Required)

  • :include_defaults (Boolean)

    Whether default mapping values should be returned as well

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



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

def get_field_mapping(arguments={})
  raise ArgumentError, "Required argument 'field' missing" unless arguments[:field]
  valid_params = [ :include_defaults ]

  method = 'GET'
  path   = Utils.__pathify(
             Utils.__listify(arguments[:index]),
             Utils.__listify(arguments[:type]),
             '_mapping', 'field',
             Utils.__listify(arguments[:field])
           )
  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

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

#get_mapping(arguments = {}) ⇒ Object

Return the mapping definitions for all indices, or specific indices/types.

Examples:

Get all mappings in the cluster


client.indices.get_mapping

Get mapping for a specific index


client.indices.get_mapping index: 'foo'

Get mapping for a specific type in a specific index


client.indices.get_mapping index: 'foo', type: 'baz'

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names; use _all or empty string for all indices

  • :type (List)

    A comma-separated list of document types

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



25
26
27
28
29
30
31
32
# File 'lib/elasticsearch/api/actions/indices/get_mapping.rb', line 25

def get_mapping(arguments={})
  method = 'GET'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_mapping'
  params = {}
  body = nil

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

#get_settings(arguments = {}) ⇒ Object

Return the settings for all indices, or a list of indices.

Examples:

Get settings for all indices


client.indices.get_settings

Get settings for an index named myindex


client.indices.get_settings index: 'myindex'

Options Hash (arguments):

  • :index (List)

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

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



21
22
23
24
25
26
27
28
# File 'lib/elasticsearch/api/actions/indices/get_settings.rb', line 21

def get_settings(arguments={})
  method = 'GET'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_settings'
  params = {}
  body   = nil

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

#get_template(arguments = {}) ⇒ Object

Note:

Use the Cluster::Actions#state API to get a list of all templates.

Get a single index template.

Examples:

Get a template named mytemplate


client.indices.get_template name: 'mytemplate'

Options Hash (arguments):

  • :name (String)

    The name of the template (Required)

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



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

def get_template(arguments={})
  method = 'GET'
  path   = Utils.__pathify '_template', Utils.__escape(arguments[:name])
  params = {}
  body = nil

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

#get_warmer(arguments = {}) ⇒ Object

Get one or more warmers for an index.

Examples:

Get all warmers


client.indices.get_warmer index: '_all'

Get all warmers matching a wildcard expression


client.indices.get_warmer index: '_all', name: 'ba*'

Get all warmers for a single index


client.indices.get_warmer index: 'foo'

Get a specific warmer


client.indices.get_warmer index: 'foo', name: 'bar'

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names to restrict the operation; use _all to perform the operation on all indices (Required)

  • :name (String)

    The name of the warmer (supports wildcards); leave empty to get all warmers

  • :type (List)

    A comma-separated list of document types to restrict the operation; leave empty to perform the operation on all types

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



32
33
34
35
36
37
38
39
40
# File 'lib/elasticsearch/api/actions/indices/get_warmer.rb', line 32

def get_warmer(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  method = 'GET'
  path   = Utils.__pathify( Utils.__listify(arguments[:index]), '_warmer', Utils.__escape(arguments[:name]) )
  params = {}
  body   = nil

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

#open(arguments = {}) ⇒ Object

Open a previously closed index (see the #close API).

Examples:

Open index named myindex


client.indices.open index: 'myindex'

Options Hash (arguments):

  • :index (String)

    The name of the index (Required)

  • :timeout (Time)

    Explicit operation timeout

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



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

def open(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  valid_params = [ :timeout ]

  method = 'POST'
  path   = Utils.__pathify Utils.__escape(arguments[:index]), '_open'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body = nil

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

#optimize(arguments = {}) ⇒ Object

Note:

The optimize operation is handled automatically by Elasticsearch, you don’t need to perform it manually. The operation is expensive in terms of resources (I/O, CPU, memory) and can take a long time to finish, potentially reducing operability of your cluster; schedule the manual optimization accordingly.

Perform an index optimization.

The “optimize” operation merges the index segments, increasing search performance. It corresponds to a Lucene “merge” operation.

Examples:

Fully optimize an index (merge to one segment)


client.indices.optimize index: 'foo', max_num_segments: 1, wait_for_merge: false

Options Hash (arguments):

  • :index (List)

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

  • :flush (Boolean)

    Specify whether the index should be flushed after performing the operation (default: true)

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore missing ones (options: none, missing)

  • :max_num_segments (Number)

    The number of segments the index should be merged into (default: dynamic)

  • :only_expunge_deletes (Boolean)

    Specify whether the operation should only expunge deleted documents

  • :refresh (Boolean)

    Specify whether the index should be refreshed after performing the operation (default: true)

  • :wait_for_merge (Boolean)

    Specify whether the request should block until the merge process is finished (default: true)

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/elasticsearch/api/actions/indices/optimize.rb', line 36

def optimize(arguments={})
  valid_params = [
    :flush,
    :ignore_indices,
    :max_num_segments,
    :only_expunge_deletes,
    :operation_threading,
    :refresh,
    :wait_for_merge ]

  method = 'POST'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_optimize'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body = nil

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

#put_alias(arguments = {}) ⇒ Object

Create or update a single index alias.

See the #update_aliases for performing operations with index aliases in bulk.

Examples:

Create an alias for current month


client.indices.put_alias index: 'logs-2013-06', name: 'current-month'

Create an alias for multiple indices


client.indices.put_alias index: 'logs-2013-06', name: 'year-2013'
client.indices.put_alias index: 'logs-2013-05', name: 'year-2013'

Options Hash (arguments):

  • :index (String)

    The name of the index with an alias

  • :name (String)

    The name of the alias to be created or updated

  • :body (Hash)

    The settings for the alias, such as routing or filter

  • :timeout (Time)

    Explicit timestamp for the document

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/elasticsearch/api/actions/indices/put_alias.rb', line 26

def put_alias(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'name' missing"  unless arguments[:name]
  valid_params = [ :timeout ]

  method = 'PUT'
  path   = Utils.__pathify Utils.__escape(arguments[:index]), '_alias', Utils.__escape(arguments[:name])

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = arguments[:body]

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

#put_mapping(arguments = {}) ⇒ Object

Create or update mapping.

Pass the mapping definition(s) in the :body argument.

Examples:

Create or update a mapping for a specific document type


client.indices.put_mapping index: 'myindex', type: 'mytype', body: {
  mytype: {
    properties: {
      title: { type: 'string', analyzer: 'snowball' }
    }
  }
}

Options Hash (arguments):

  • :body (Hash)

    The mapping definition (Required)

  • :index (List)

    A comma-separated list of index names; use _all to perform the operation on all indices (Required)

  • :type (String)

    The name of the document type (Required)

  • :ignore_conflicts (Boolean)

    Specify whether to ignore conflicts while updating the mapping (default: false)

  • :timeout (Time)

    Explicit operation timeout

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/elasticsearch/api/actions/indices/put_mapping.rb', line 30

def put_mapping(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'type' missing"  unless arguments[:type]
  raise ArgumentError, "Required argument 'body' missing"  unless arguments[:body]
  valid_params = [ :ignore_conflicts, :timeout ]

  method = 'PUT'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), Utils.__escape(arguments[:type]), '_mapping'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = arguments[:body]

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

#put_settings(arguments = {}) ⇒ Object

Update the settings for one or multiple indices.

Examples:

Change the number of replicas for all indices


client.indices.put_settings body: { index: { number_of_replicas: 0 } }

Change the number of replicas for a specific index


client.indices.put_settings index: 'myindex', body: { index: { number_of_replicas: 0 } }

Disable “flush” for all indices


client.indices.put_settings body: { 'index.translog.disable_flush' => true }

Allocate specific index on specific nodes


client.indices.put_settings index: 'my-big-index',
                            body: { 'index.routing.allocation.require.tag' => 'bigbox' }

Options Hash (arguments):

  • :body (Hash)

    The index settings to be updated (Required)

  • :index (List)

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

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



33
34
35
36
37
38
39
40
41
# File 'lib/elasticsearch/api/actions/indices/put_settings.rb', line 33

def put_settings(arguments={})
  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
  method = 'PUT'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_settings'
  params = {}
  body   = arguments[:body]

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

#put_template(arguments = {}) ⇒ Object

Create or update an index template.

Examples:

Create a template for all indices starting with logs-


client.indices.put_template :name => 'foo',
                            :body => { template: 'logs-*', settings: { 'index.number_of_shards' => 1 } }

Options Hash (arguments):

  • :name (String)

    The name of the template (Required)

  • :body (Hash)

    The template definition (Required)

  • :order (Number)

    The order for this template when merging multiple matching ones (higher numbers are merged later, overriding the lower numbers)

  • :timeout (Time)

    Explicit operation timeout

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/elasticsearch/api/actions/indices/put_template.rb', line 22

def put_template(arguments={})
  raise ArgumentError, "Required argument 'name' missing" unless arguments[:name]
  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
  valid_params = [ :order, :timeout ]

  method = 'PUT'
  path   = Utils.__pathify '_template', Utils.__escape(arguments[:name])

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = arguments[:body]

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

#put_warmer(arguments = {}) ⇒ Object

Create or update an index warmer.

An index warmer will run before an index is refreshed, ie. available for search. It allows you to register “heavy” queries with popular filters, facets or sorts, increasing performance when the index is searched for the first time.

Examples:

Register a warmer which will populate the caches for published filter and sorting on created_at


client.indices.put_warmer index: 'myindex',
                          name: 'main',
                          body: {
                            query: { filtered: { filter: { term: { published: true } } } },
                            sort:  [ "created_at" ]
                          }

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names to register the warmer for; use _all or empty string to perform the operation on all indices (Required)

  • :name (String)

    The name of the warmer (Required)

  • :type (List)

    A comma-separated list of document types to register the warmer for; leave empty to perform the operation on all types

  • :body (Hash)

    The search request definition for the warmer (query, filters, facets, sorting, etc) (Required)

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/elasticsearch/api/actions/indices/put_warmer.rb', line 31

def put_warmer(arguments={})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'name' missing" unless arguments[:name]
  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
  method = 'PUT'
  path   = Utils.__pathify( Utils.__listify(arguments[:index]),
                            Utils.__listify(arguments[:type]),
                            '_warmer',
                            Utils.__listify(arguments[:name]) )
  params = {}
  body   = arguments[:body]

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

#refresh(arguments = {}) ⇒ Object

Note:

The refresh operation can adversely affect indexing throughput when used too frequently.

Refresh the index and to make the changes (creates, updates, deletes) searchable.

By default, Elasticsearch has a delay of 1 second until changes to an index are available for search; the delay is configurable, see #put_settings.

You can trigger this operation explicitely, for example when performing a sequence of commands in integration tests, or when you need to perform a manual “synchronization” of the index with an external system at given moment.

Examples:

Refresh an index named myindex


client.indices.refresh index: 'myindex'

Options Hash (arguments):

  • :index (List)

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

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore missing ones (options: none, missing)

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/elasticsearch/api/actions/indices/refresh.rb', line 28

def refresh(arguments={})
  valid_params = [ :ignore_indices ]

  method = 'POST'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_refresh'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

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

#segments(arguments = {}) ⇒ Object

Return information about segments for one or more indices.

The response contains information about segment size, number of documents, deleted documents, etc. See also #optimize.

Options Hash (arguments):

  • :index (List)

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

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore missing ones (options: none, missing)

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/elasticsearch/api/actions/indices/segments.rb', line 18

def segments(arguments={})
  valid_params = [ :ignore_indices ]

  method = 'GET'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_segments'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

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

#snapshot_index(arguments = {}) ⇒ Object

Deprecated.

The shared gateway has been deprecated [github.com/elasticsearch/elasticsearch/issues/2458]

When using the shared storage gateway, manually trigger the snapshot operation.

Options Hash (arguments):

  • :index (List)

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

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore missing ones (options: none, missing)

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



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

def snapshot_index(arguments={})
  valid_params = [ :ignore_indices ]

  method = 'POST'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_gateway/snapshot'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

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

#stats(arguments = {}) ⇒ Object

Return statistical information about one or more indices.

The response contains comprehensive statistical information about metrics related to index: how much time did indexing, search and other operations take, how much disk space it takes, how much memory filter caches or field data require, etc.

Examples:

Get default statistics for all indices


client.indices.stats

Get all available statistics for a single index


client.indices.stats index: 'foo', all: true

Get statistics about documents and disk size for multiple indices


client.indices.stats index: ['foo', 'bar'], clear: true, docs: true, store: true

Get statistics about filter cache and field data, for all indices


client.indices.stats clear: true, fielddata: true , filter_cache: true, fields: '*'

Get statistics about searches, with segmentation for different search groups


client.indices.stats clear: true, search: true , groups: ['groupA', 'groupB']

Options Hash (arguments):

  • :search_groups (List)

    A comma-separated list of search groups to include in the search statistics

  • :all (Boolean)

    Return all available information

  • :clear (Boolean)

    Reset the default level of detail

  • :docs (Boolean)

    Return information about indexed and deleted documents

  • :fielddata (Boolean)

    Return information about field data

  • :fields (Boolean)

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

  • :filter_cache (Boolean)

    Return information about filter cache

  • :flush (Boolean)

    Return information about flush operations

  • :get (Boolean)

    Return information about get operations

  • :groups (Boolean)

    A comma-separated list of search groups for search statistics

  • :id_cache (Boolean)

    Return information about ID cache

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore missing ones (options: none, missing)

  • :index (List)

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

  • :indexing (Boolean)

    Return information about indexing operations

  • :indexing_types (List)

    A comma-separated list of document types to include in the indexing statistics

  • :merge (Boolean)

    Return information about merge operations

  • :refresh (Boolean)

    Return information about refresh operations

  • :search (Boolean)

    Return information about search operations; use the groups parameter to include information for specific search groups

  • :store (Boolean)

    Return information about the size of the index

  • :warmer (Boolean)

    Return information about warmers

See Also:

Since:

  • The fielddata, filter_cache and id_cache metrics are available from version 0.90.

Parameters:

  • (defaults to: {})

    a customizable set of options



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
# File 'lib/elasticsearch/api/actions/indices/stats.rb', line 62

def stats(arguments={})
  valid_params = [
    :all,
    :clear,
    :docs,
    :fielddata,
    :fields,
    :filter_cache,
    :flush,
    :get,
    :groups,
    :id_cache,
    :ignore_indices,
    :indexing,
    :merge,
    :refresh,
    :search,
    :store,
    :warmer ]

  method = 'GET'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_stats'

  params = Utils.__validate_and_extract_params arguments, valid_params
  params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
  params[:groups] = Utils.__listify(params[:groups]) if params[:groups]

  body   = nil

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

#status(arguments = {}) ⇒ Object

Return information about one or more indices

Examples:

Get information about all indices


client.indices.status

Get information about a specific index


client.indices.status index: 'foo'

Get information about shard recovery for a specific index


client.indices.status index: 'foo', recovery: true

Options Hash (arguments):

  • :index (List)

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

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore missing ones (options: none, missing)

  • :recovery (Boolean)

    Return information about shard recovery (progress, size, etc)

  • :snapshot (Boolean)

    Return information about snapshots (when shared gateway is used)

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



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

def status(arguments={})
  valid_params = [
    :ignore_indices,
    :recovery,
    :snapshot ]

  method = 'GET'
  path   = Utils.__pathify Utils.__listify(arguments[:index]), '_status'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

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

#update_aliases(arguments = {}) ⇒ Object

Perform multiple operation on index aliases in a single request.

Pass the actions (add, remove) in the body argument.

Examples:

Add multiple indices to a single alias


client.indices.update_aliases body: {
  actions: [
    { add: { index: 'logs-2013-06', alias: 'year-2013' } },
    { add: { index: 'logs-2013-05', alias: 'year-2013' } }
  ]
}

Swap an alias (atomic operation)


client.indices.update_aliases body: {
  actions: [
    { remove: { index: 'logs-2013-06', alias: 'current-month' } },
    { add:    { index: 'logs-2013-07', alias: 'current-month' } }
  ]
}

Options Hash (arguments):

  • :body (Hash)

    The operations definition and other configuration (Required)

  • :timeout (Time)

    Explicit operation timeout

Raises:

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/elasticsearch/api/actions/indices/update_aliases.rb', line 33

def update_aliases(arguments={})
  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
  valid_params = [ :timeout ]

  method = 'POST'
  path   = "_aliases"

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = arguments[:body]

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

#validate_query(arguments = {}) ⇒ Object

Validate a query

Examples:

Validate a simple query string query


client.indices.validate_query index: 'myindex', q: 'title:foo AND body:bar'

Validate an invalid query (with explanation)


client.indices.validate_query index: 'myindex', q: '[[[ BOOM! ]]]', explain: true

Validate a DSL query (with explanation)


client.indices.validate_query index: 'myindex',
                              explain: true,
                              body: {
                                filtered: {
                                  query: {
                                    match: {
                                      title: 'foo'
                                    }
                                  },
                                  filter: {
                                    range: {
                                      published_at: {
                                        from: '2013-06-01'
                                      }
                                    }
                                  }
                                }
                              }

Options Hash (arguments):

  • :index (List)

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

  • :type (List)

    A comma-separated list of document types to restrict the operation; leave empty to perform the operation on all types

  • :body (Hash)

    The query definition (without the top-level query element)

  • :explain (Boolean)

    Return detailed information about the error

  • :ignore_indices (String)

    When performed on multiple indices, allows to ignore missing ones (options: none, missing)

  • :source (String)

    The URL-encoded query definition (instead of using the request body)

  • :q (String)

    Query in the Lucene query string syntax

See Also:

Parameters:

  • (defaults to: {})

    a customizable set of options



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/elasticsearch/api/actions/indices/validate_query.rb', line 50

def validate_query(arguments={})
  valid_params = [
    :q,
    :explain,
    :ignore_indices,
    :source ]

  method = 'GET'
  path   = Utils.__pathify Utils.__listify(arguments[:index]),
                           Utils.__listify(arguments[:type]),
                           '_validate/query'

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = arguments[:body]

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