Method: Elasticsearch::API::Indices::Actions#put_mapping

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

#put_mapping(arguments = {}) ⇒ Object

Update field mappings. Add new fields to an existing data stream or index. You can use the update mapping API to:

  • Add a new field to an existing index

  • Update mappings for multiple indices in a single request

  • Add new properties to an object field

  • Enable multi-fields for an existing field

  • Update supported mapping parameters

  • Change a field’s mapping using reindexing

  • Rename a field using a field alias

Learn how to use the update mapping API with practical examples in the Update mapping API examples guide.

Parameters:

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

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    A comma-separated list of index names the mapping should be added to (supports wildcards); use ‘_all` or omit to add the mapping on all indices. (Required)

  • :allow_no_indices (Boolean)

    If ‘false`, the request returns an error if any wildcard expression, index alias, or `_all` value targets only missing or closed indices. This behavior applies even if the request targets other open indices. Server default: true.

  • :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`. Server default: open.

  • :ignore_unavailable (Boolean)

    If ‘false`, the request returns an error if it targets a missing or closed index.

  • :master_timeout (Time)

    Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Server default: 30s.

  • :timeout (Time)

    Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error. Server default: 30s.

  • :write_index_only (Boolean)

    If ‘true`, the mappings are applied only to the current write index for the target.

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

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



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

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

  defined_params = [: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?

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]

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

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = Elasticsearch::API::HTTP_PUT
  path   = "#{Utils.listify(_index)}/_mapping"
  params = Utils.process_params(arguments)

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