How to do it...

You can explicitly create a mapping by adding a new document in Elasticsearch. For this, we will perform the following steps:

  1. Create an index like so:
PUT test

The answer will be as follows:

{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "test"
}
  1. Put a document in the index, as shown in the following code:
PUT test/_doc/1
{"name":"Paul", "age":35}

The answer will be as follows:

{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
  1. Get the mapping with the following code:
GET test/_mapping

  1. The result mapping that's autocreated by Elasticsearch should be as follows:
{
"test" : {
"mappings" : {
"properties" : {
"age" : {
"type" : "long"
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
  1. To delete the index, you can call the following:
DELETE test

The answer will be as follows:

{
"acknowledged" : true
}