Managing indices
In the previous recipe, we saw how to initialize a client to send calls to an Elasticsearch cluster. In this recipe, we will look at how to manage indices via client calls.
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 from the Creating a client recipe in this chapter.
The full code for this recipe can be found in the chapter_16/indices_management.py
file.
How to do it…
In Python, managing the life cycle of your indices is very easy. We will perform the following steps:
We initialize a client:
import elasticsearch es = elasticsearch.Elasticsearch() index_name = "my_index"
We need to check if the index exists, and, if so, we need to delete it:
if es.indices.exists(index_name): es.indices.delete(index_name)
All the
indices
methods are available...