Managing indices
In the previous recipe, we learned how to initialize a client to send calls to an Elasticsearch cluster. In this recipe, we will learn how to manage indices via client calls.
Getting ready
You will need an up-and-running Elasticsearch installation, as described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.
You will also need the Python-installed packages from the Creating a client recipe in this chapter.
The full code for this recipe can be found in the ch15/code/indices_management.py
file.
How to do it…
In Python, managing the life cycle of your indices is very easy. To do this, perform the following steps:
- First, you must initialize a client reading credential from environment variables (
ES_USER
/ES_PASSWORD
) and disablessl
key verification due to the self-signed SSL certificate, as shown in the following code:import elasticsearch import os import ssl es = elasticsearch.Elasticsearch...