9951 explained code solutions for 126 technologies


elasticsearchHow do I update a mapping in Elasticsearch?


Updating a mapping in Elasticsearch is a two-step process. First, you need to delete the existing mapping, and then you can add the new mapping.

Example code

# Delete existing mapping
curl -X DELETE localhost:9200/my_index

# Add new mapping
curl -X PUT localhost:9200/my_index -H 'Content-Type: application/json' -d '
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text"
      }
    }
  }
}'

Output example

{"acknowledged":true}
  • curl -X DELETE localhost:9200/my_index: This command sends an HTTP DELETE request to the Elasticsearch server running on localhost:9200 for the index named my_index.
  • curl -X PUT localhost:9200/my_index: This command sends an HTTP PUT request to the Elasticsearch server running on localhost:9200 for the index named my_index.
  • -H 'Content-Type: application/json': This specifies the content type of the request body as JSON.
  • -d '<mapping>': This specifies the mapping to be added to the index.

Helpful links

Edit this code on GitHub