Managing mappings include the mapping
After creating an index, the next step is to add some type mappings to it. We have already seen how to include a mapping via the REST API in Chapter 4, Basic Operations.
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.
You also need the Python installed packages of Creating a client recipe of this chapter.
The code for this recipe is in the chapter_16/mapping_management.py
file.
How to do it…
After having initialized a client and created an index, the steps for managing the indices are as follows:
Create a mapping.
Retrieve a mapping.
These steps are easily managed with the following code:
We initialize the client:
import elasticsearch es = elasticsearch.Elasticsearch()
We create an index:
index_name = "my_index" type_name = "my_type" if es.indices.exists(index_name): ...