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 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.
A Maven tool or an IDE that natively supports it for Java programming, such as Visual Studio Code, Eclipse, or IntelliJ IDEA, must be installed.
The code for this recipe is in the ch13/elasticsearch-java-client
directory and the referred class is IndicesOperations
.
How to do it...
An Elasticsearch client maps all index operations under the indices
object of the client, such as create
, delete
, exists
, open
, close
, and optimize
. The following steps retrieve a client and execute the main operations on the indices:
- First, we import the required classes, as shown in the following code:
import...