Link Search Menu Expand Document Documentation Menu

Create or update mappings

Introduced 1.0

If you want to create or add mappings and fields to an index, you can use the put mapping API operation. For an existing mapping, this operation updates the mapping.

You can’t use this operation to update mappings that already map to existing data in the index. You must first create a new index with your desired mappings, and then use the reindex API operation to map all the documents from your old index to the new index. If you don’t want any downtime while you re-index your indexes, you can use aliases.

Endpoints

PUT /<target-index>/_mapping
PUT /<target-index1>,<target-index2>/_mapping

Path parameters

The only required path parameter is the index with which to associate the mapping. If you don’t specify an index, you will get an error. You can specify a single index, or multiple indexes separated by a comma as follows:

PUT /<target-index>/_mapping
PUT /<target-index1>,<target-index2>/_mapping

Query parameters

Optionally, you can add query parameters to make a more specific request. For example, to skip any missing or closed indexes in the response, you can add the ignore_unavailable query parameter to your request as follows:

PUT /sample-index/_mapping?ignore_unavailable

The following table defines the put mapping query parameters:

Parameter Data type Description
allow_no_indices Boolean Whether to ignore wildcards that don’t match any indexes. Default is true.
expand_wildcards String Expands wildcard expressions to different indexes. Combine multiple values with commas. Available values are all (match all indexes), open (match open indexes), closed (match closed indexes), hidden (match hidden indexes), and none (do not accept wildcard expressions), which must be used with open, closed, or both. Default is open.
ignore_unavailable Boolean If true, OpenSearch does not include missing or closed indexes in the response.
cluster_manager_timeout Time How long to wait for a connection to the cluster manager node. Default is 30s.
timeout Time How long to wait for the response to return. Default is 30s.
write_index_only Boolean Whether OpenSearch should apply mapping updates only to the write index.

Request body fields

properties

The request body must contain properties, which has all of the mappings that you want to create or update.

{
  "properties":{
    "color":{
      "type": "text"
    },
    "year":{
      "type": "integer"
    }
  }
}

dynamic

You can make the document structure match the structure of the index mapping by setting the dynamic request body field to strict, as seen in the following example:

{
  "dynamic": "strict",
  "properties":{
    "color":{
      "type": "text"
    }
  }
}

Example request

The following request creates a new mapping for the sample-index index:

PUT /sample-index/_mapping

{
  "properties": {
    "age": {
      "type": "integer"
    },
    "occupation":{
      "type": "text"
    }
  }
}

Example response

Upon success, the response returns "acknowledged": true.

{
    "acknowledged": true
}
350 characters left

Have a question? .

Want to contribute? or .