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.

Example

  1. PUT /sample-index/_mapping
  2. {
  3. "properties": {
  4. "age": {
  5. "type": "integer"
  6. },
  7. "occupation":{
  8. "type": "text"
  9. }
  10. }
  11. }

Path and HTTP methods

  1. PUT /<target-index>/_mapping
  2. PUT /_mapping

You can also use the put mapping operation to update multiple indexes with one request.

  1. PUT /<target-index1>,<target-index2>/_mapping

URL parameters

All put mapping parameters are optional.

ParameterData TypeDescription
<target-index>N/ASpecifies an index with which to associate the mapping. If you do not specify this parameter, OpenSearch adds the mapping to all indexes within the cluster.
allow_no_indicesBooleanWhether to ignore wildcards that don’t match any indexes. Default is true.
expand_wildcardsStringExpands 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_unavailableBooleanIf true, OpenSearch does not include missing or closed indexes in the response.
master_timeoutTimeHow long to wait for a connection to the master node. Default is 30s.
timeoutTimeHow long to wait for the response to return. Default is 30s.
write_index_onlyBooleanWhether OpenSearch should apply mapping updates only to the write index.

Request body

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

  1. {
  2. "properties":{
  3. "color":{
  4. "type": "text"
  5. },
  6. "year":{
  7. "type": "integer"
  8. }
  9. }
  10. }

Response

  1. {
  2. "acknowledged": true
  3. }