Managing mappings
After creating an index, the next step is to add some mapping to it. We have already seen how to put a mapping via REST API in Chapter 4, Standard Operations. In this recipe, we will see how to manage mappings via official Python client and PyES.
Getting ready
You need a working ElasticSearch cluster and required packages of the Creating a client recipe of this chapter.
The code of this recipe is in chapter_11/mapping_management.py
and chapter_11/mapping_management_pyes.py
.
How to do it...
After having initialized a client and created an index, the steps required for managing the indices are as follows:
- Create a mapping
- Retrieve a mapping
- Delete a mapping
These steps are easily managed with code as follows:
- We initialize the client as follows:
import elasticsearch es = elasticsearch.Elasticsearch()
- We create an index as follows:
index_name = "my_index" type_name = "my_type" es.indices.create(index_name) es.cluster.health(wait_for_status="yellow")
- We put...