Using explicit mapping creation
If you consider an index as a database in the SQL world, a mapping is similar to the table definition.
ElasticSearch is able to understand the structure of the document that you are indexing (reflection) and creates the mapping definition automatically (explicit mapping creation).
Getting ready
You will need a working ElasticSearch cluster, an index named test (see the Creating an index recipe in Chapter 4, Basic Operations), and basic knowledge of JSON.
How to do it...
To create an explicit mapping, perform the following steps:
- You can explicitly create a mapping by adding a new document in ElasticSearch:
- On a Linux shell:
#create an index curl -XPUT http://127.0.0.1:9200/test #{acknowledged":true} #put a document curl -XPUT http://127.0.0.1:9200/test/mytype/1 -d '{"name":"Paul", "age":35}' # {"ok":true,"_index":"test","_type":"mytype","_id":"1","...
- On a Linux shell: