Managing mappings
After creating an index, the next step is to add some mappings to it. We learned how to include a mapping via the REST API in Chapter 3, Basic Operations.
Getting ready
You will need an up-and-running Elasticsearch installation, which we described how to get in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.
You will also need the Python packages that we installed in the Creating a client recipe in this chapter.
The code for this recipe can be found in the ch15/code/mapping_management.py
file.
How to do it…
After initializing a client and creating an index, you can manage its indices. To do so, you must do the following:
- Create a mapping.
- Retrieve a mapping.
Perform the following steps:
- First, initialize the client with auth, as in Managing indices section of this chapter.
- Then, create an index, as follows:
index_name = "my_index" if es.indices.exists(index=index_name...