The Elasticsearch List Indexes Tutorial

Have a Database Problem? Speak with an Expert for Free
Get Started >>

Introduction

There are multiple ways to list all of the indexes contained in an Elasticsearch cluster. One common way of doing this is to use cURL and Kibana to issue HTTP requests to communicate with the Elasticsearch cluster to have it return all of the index names and their respective UUIDs. The Elasticsearch list indexes tutorial will explain how to connect to Elasticsearch and list the indexes stored on a cluster. Note that the methods that will be covered in this tutorial can be used on a Windows, Mac or Linux system.

Prerequisites

  • A stable version of Elasticsearch, that still provides long-term support, or LTS, must be installed on the local system to have Elasticsearch list indexes. Note that Elasticsearch v7.5. is the latest version as of January 2020.

  • The web-based Kibana user interface must also be installed on the local machine. Alternatively, accessing Elasticsearch in a terminal or command-prompt window using cURL requests will retrieve the cluster’s indexes.

Install cURL for Elasticsearch requests

For users who don’t want to use the Kibana GUI, cURL is required to submit requests to the Elasticsearch cluster. Execute the curl -V command in a Linux or MacOS terminal to confirm cURL is installed and obtain its version number.

Install cURL on MacOS

Install cURL on a MacOS using the following Homebrew command:

1
brew install curl

Ruby can also be used to install cURL with the following command:

1
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - /dev/null 2- /dev/null

Install cURL on Ubuntu

The repositories should always be update, using the following command, before any packages are installed on Ubuntu:

1
sudo apt update && sudo apt-get update

While most current distros of Linux come with cURL pre-installed, the APT repository can be used to install the cURL library, if needed, with the following command:

1
sudo apt install curl

Install Java for Elasticsearch

Newer versions of Elasticsearch are bundled with its own OpenJDK, the open-source alternative to Oracle’s Java Development Kit. However, a customized Java installation may also be used. To confirm Java has been installed, execute the java --version or update-java-alternatives -l commands to obtain information about the Java and JDK installations.

Install Java on macOS or Windows

Oracle has an interactive Java installer for both Windows and MacOS, but using it now requires creating an account and signing in before being allowed to execute downloads.

However, OpenJDK does allow useres to download and install binaries for all operating systems without having to create an account.

Install Java on Ubuntu

The following example uses the APT-GET repository to install OpenJDK 11 on a Debian-based flavor of Linux, such as Ubuntu or Linux Mint:

1
sudo apt-get install openjdk-11-jdk

The Java runtime environment can be installed on Ubuntu with the following command:

1
sudo apt-get install default-jre

Install Elasticsearch

Skip this section if Elasticsearch is already installed. If not, execute the below instructions to install Elasticsearch on the dev computer or server. The interactive MSI installer for Elasticsearch can be used to download the program on Windows machine.

Install Elasticsearch on MacOS

Execute the following brew command to “tap” the elastic Homebrew repository for Elasticsearch:

1
brew tap elastic/tap

Once the brew tap elastic/tap command has been executed, use the following brew install command to install Elasticsearch on Mac:

1
brew install elastic/tap/elasticsearch-full

Once that function has completed, execute the following elasticsearch command to start the cluster as a foreground service in a terminal window:

1
elasticsearch

The result should resemble the following screenshot:

Screenshot of Elasticsearch list indexes installing Elasticsearch on macOS with Homebrew

Elasticsearch connection

With Elasticsearch installed and the cluster working properly, execute the curl localhost:9200 command in a terminal or command-prompt window to obtain a JSON response that should resemble following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
  "name" : "Macs-MacBook-Pro.local",
  "cluster_name" : "elasticsearch_macuser",
  "cluster_uuid" : "lbja__eEQNSUSRA1wJ-CaA",
  "version" : {
    "number" : "7.5.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "8bec50e1e0ad29dad5653712cf3bb580cd1afcdf",
    "build_date" : "2020-01-15T12:11:52.313576Z",
    "build_snapshot" : false,
    "lucene_version" : "8.3.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

Note that the above JSON response contains vital information about the Elasticsearch installation and cluster.

Use Elasticsearch to create an index

cURL can also be used to make an HTTP PUT request to create a new index. The following request instructs the cluster to create the new_index:

1
curl -X PUT "localhost:9200/new_index?pretty"

NOTE: The ?pretty=true or ?pretty option will have Elasticsearch format the JSON response into a more readable form.

The results should resemble the following image:

Screenshot using cURL to PUT new Elasticsearch index for Elasticsearch list indexes example

List indexes in Elasticsearch

A HTTP request, that points to /_cat/indices/ in the request header’s URL, is needed to obtain the Elasticsearch cluster’s indices.

Use cURL to list indices for Elasticsearch

Execute the following cURL request to return a list of all of the Elasticsearch indexes:

1
curl localhost:9200/_cat/indices

Alternatively, use the following -v (verbose) option to obtain a more detailed response that will also contain the names of the indexes:

1
curl -v "localhost:9200/_cat/indices"

It should be noted that the above requests should return an HTTP response of 200 OK along with a list of the name, health status and UUID of each index.

NOTE: The request should also return all of the cluster’s built-in default indexes, such as .kibana. The use of the -X option is often unnecessary in newer versions of cURL.

Use Kibana to list indices for Elasticsearch

If there is a web-based Kibana user interface installed and running, the same results can be obtained by navigating to http://localhost:5601/ in a browser tab and executing the following request in the “Dev Tools” console:

1
GET _cat/indices

As with the terminal-based cURL requests, Kibana should return the status, name and UUID for each index.

The results should look like the flowing image:

Screenshot of accessing Elasticsearch to list indexes using a Kibana HTTP request

Elasticsearch get index example

To confirm a specific index exists, just pass the index name to the cluster’s domain and port URL in the request header as shown in the following example:

1
curl -iv "localhost:9200/new_index?pretty"

The command should return a combination of an HTTP and JSON response that resembles the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9200 (#0)
> GET /new_index?pretty HTTP/1.1
> Host: localhost:9200
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< content-type: application/json; charset=UTF-8
content-type: application/json; charset=UTF-8
< content-length: 379
content-length: 379

<
{
  "new_index" : {
    "aliases" : { },
    "mappings" : { },
    "settings" : {
      "index" : {
        "creation_date" : "1580134445421",
        "number_of_shards" : "1",
        "number_of_replicas" : "1",
        "uuid" : "Jju1fRHARxKv77hA8l487Q",
        "version" : {
          "created" : "7050299"
        },
        "provided_name" : "new_index"
      }
    }
  }
}
* Connection #0 to host localhost left intact
* Closing connection 0

Screenshot of of a cURL request to Elasticsearch to get an index

NOTE: The request URL must be enclosed in quotation marks whenever using options like ?pretty. However, the same GET request can be executed in Kibana using GET new_index. Here it is not necessary to use the ?pretty option in the Kibana request as the UI automatically formats the JSON responses.

Conclusion

This Elasticsearch list indexes tutorial explained how to connect to Elasticsearch and list the indexes stored on a cluster. The tutorial specifically covered how to install cURL for Elasticsearch requests on MacOS, Ubuntu and Windows, how to install Java for Elasticsearch on MacOS, Windows and Ubuntu and how to install Elasticsearch and make an Elasticsearch connection with the local system. The article also explained how to use Elasticsearch to create an index, list the indexes in Elasticsearch with cURL and provided an Elasticsearch get-index example. Remember that the request URL must be enclosed in quotation marks whenever options like ?pretty are used. However, the same GET request can be executed in Kibana using GET new_index without using the ?pretty option as the UI automatically formats the JSON responses in Kibana.

Pilot the ObjectRocket Platform Free!

Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.

Get Started

Keep in the know!

Subscribe to our emails and we’ll let you know what’s going on at ObjectRocket. We hate spam and make it easy to unsubscribe.