Elasticsearch show indices
Elasticsearch is a distributed, free and open search and analytics engine for all types of data, including textual, numerical, geospatial, structured, and unstructured. Elasticsearch is built on top of the Apache Lucene project which means it borrows the general architecture. However, Elasticsearch comes with comprehensive tools and features that make it a revolutionary tool.
The essence of this tutorial is to show you how you can retrieve and view all the indicis within your Elasticsearch cluster.
Let’s dive in.
What’s an Elasticsearch Index?
An Elasticsearch index is a collection of documents that are related to each other. Elasticsearch stores data as JSON documents. Each document correlates a set of keys (names of fields or properties) with their corresponding values (strings, numbers, Booleans, dates, arrays of values, geolocations, or other types of data).
The following diagram illustrates the equivalence of Elasticsearch architecture to relational database.
- MySQL => Databases => Tables => Columns/Rows
- Elasticsearch => Indices => Types => Documents with Properties
An Elasticsearch cluster can contain multiple Indices (databases), which in turn contain multiple Types (tables). These types hold multiple Documents (rows), and each document has Properties(columns).
Elasticsearch cat Indices API
Elasticsearch utilizes RESTful APIs extensively. Hence, we can use the cat
API endpoint to get high-level information about the indices in a Elasticsearch cluster.
Request Syntax
The request syntax is as shown:
GET /_cat/indices/<target>
GET /_cat/indices
If the Elasticsearch security features are enabled, you must have themonitor
ormanage
privilege on the target cluster.
Upon successful execution, the query should return information about the index including:
- Shard count
- Document count
- Deleted document count
- Primary store size
- Total store size of all shards, including shard replicas
Query Parameters
The request accepts the following query parameters:
bytes
(Optional) Unit used to display byte values.format
(Optional, string) Short version of the HTTP accept header. Valid values include JSON, YAML, etc.h
(Optional, string) Comma-separated list of column names to display.health
(Optional, string) Health status used to limit returned indices. Valid values are:green``yellow``red
By default, the response includes indices of any health status.help
(Optional, Boolean) Iftrue
, the response includes help information. Defaults tofalse
.include_unloaded_segments
(Optional, Boolean) Iftrue
, the response includes information from segments that are not loaded into memory. Defaults tofalse
.master_timeout
(Optional) Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Defaults to30s
.pri
(primary shards)(Optional, Boolean) Iftrue
, the response only includes information from primary shards. Defaults tofalse
.s
(Optional, string) Comma-separated list of column names or column aliases used to sort the response.time
(Optional) Unit used to display time values.v
(Optional, Boolean) Iftrue
, the response includes column headings. Defaults tofalse
.expand_wildcards
(Optional, string) Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such asopen,hidden
. Valid values are:all
Match any data stream or index, including hidden ones.open
Match open, non-hidden indices. Also matches any non-hidden data stream.closed
Match closed, non-hidden indices. Also matches any non-hidden data stream. Data streams cannot be closed.hidden
Match hidden data streams and hidden indices. Must be combined withopen
,closed
, or both.none
Wildcard patterns are not accepted.
Example
The following example returns all the indices in the cluster:
GET _cat/indices?v=true
cURL version is as shown:
curl -XGET "http://localhost:9200/_cat/indices?v=true" -H "kbn-xsrf: reporting"
The resulting output is as shown:
If you only want the index name, you can select the index column as shown:
GET _cat/indices?v=true&h=index
cURL version
curl -XGET "http://localhost:9200/_cat/indices?v=true&h=index" -H "kbn-xsrf: reporting"
Output:
index
earthquake
.ds-logs-enterprise_search.audit-default-2022.08.20-000001
.ds-logs-crawler-default-2022.08.20-000001
.ds-logs-enterprise_search.api-default-2022.08.20-000001
.ds-logs-app_search.analytics-default-2022.08.20-000001
Example 2
To get information for a specific index, we can run the query:
GET _cat/indices/.kibana?v=true
cURL version.
curl -XGET "http://localhost:9200/_cat/indices/.kibana?v=true" -H "kbn-xsrf: reporting"
The query above should return information about the kibana
index as shown:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .kibana_8.3.3_001 np8zzpriSiSZm3xz2b2N9w 1 1 628 53 6.8mb 3.4mb
Conclusion
In this article, you learned how to use the Elasticsearch cat
index API to retrieve information about the indices in the Elasticsearch cluster.
We hope you found this helpful. Feel free to leave a comment below or contact us.
See you in the next one!!