How to do it...

The HTTP method to put a mapping is PUT (POST also works). The URL format for putting a mapping is as follows:

http://<server>/<index_name>/_mapping

To put a mapping in an index, we will perform the following steps:

  1. If we consider a possible order data model to be used as a mapping, the call will be as follows:
PUT /myindex/_mapping
{
"properties": {
"id": {
"type": "keyword",
"store": true
},
"date": {
"type": "date",
"store": false
},
"customer_id": {
"type": "keyword",
"store": true
},
"sent": {
"type": "boolean"
},
"name": {
"type": "text"
},
"quantity": {
"type": "integer"
},
"vat": {
"type": "double",
"index": false
}
}
}
  1. In the case of a success, the result returned by Elasticsearch should be like this:
{
"acknowledged" : true
}