Using explicit mapping creation
If we consider the index as a database in the SQL world, the mapping is similar to the table definition.
Getting ready
You need a working ElasticSearch cluster, a test
index (refer to the Creating an index recipe in Chapter 4, Standard Operations), and basic knowledge of JSON.
How to do it...
For explicit mapping creation, we will perform the following steps:
You can explicitly create a mapping by adding a new element in ElasticSearch.
On bash:
#create an index curl -XPUT http://127.0.0.1:9200/test #{"ok":true,"acknowledged":true} #put a record curl -XPUT http://127.0.0.1:9200/test/mytype/1 -d '{"name":"Paul", "age":35}' # {"ok":true,"_index":"test","_type":"mytype","_id":"1","_version":1} #get the mapping and pretty print it curl –XGET http://127.0.0.1:9200/test/mytype/_mapping?pretty=true
The result mapping auto-created by ElasticSearch should be as follows:
{ "mytype" : { "properties" : { "age" : { "type" : "long" }, "name" :...