Using explicit mapping creation
If we consider the index as a database in the SQL world, the mapping is similar to the table definition.
Elasticsearch is able to understand the structure of the document that you are indexing (reflection) and create the mapping definition automatically (explicit mapping creation).
Getting ready
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
To execute curl
via command-line, you need to install curl
for your operative system.
To better understand examples and code in this recipe, basic knowledge of JSON is required.
How to do it...
You can explicitly create a mapping by adding a new document in Elasticsearch. We will perform the following steps:
Create an index:
curl -XPUT http://127.0.0.1:9200/test
The answer will be as follows:
{acknowledged":true}
Put a document in the index:
curl -XPUT http://127.0.0.1:9200/test/mytype/1...