How can I get all index name from Elasticsearch by using golang client library?


I am using this library in go to query from Elasticsearch.

I has some examples on querying but I am looking for a API method to get all index from Elasticsearch cluster. But I can’t find one I can use from their doc. Does anyone know what the best way to get all index? like the http api _cat/indices


Here’s a working example:

package main

import (


func main() {

    cfg := elasticsearch.Config{
        Addresses: []string{
        Username: "foo",
        Password: "bar",
    es, err := elasticsearch.NewClient(cfg)
    if err != nil {
    res, err := esapi.CatIndicesRequest{Format: "json"}.Do(context.Background(), es)
    if err != nil {
    defer res.Body.Close()


You can tweak the CatIndicesRequest to format the output for your case.
For example, if you use CatIndicesRequest{Pretty: true, Human: true}. It will return something like this:

[200 OK] green open .ent-search-actastic-workplace_search_accounts_v16                                                                           yvaDvj9RTMOoWqIpKdC_kw 1 1       1      0  12.1kb     6kb
green open .ent-search-workplace-search-content-events-ecs-ilm-logs-production-2022.01.23-000003                                        1D1BagTFQ6ypoZh2RdoUhQ 1 1       0      0    416b    208b
green open .ent-search-actastic-workplace_search_search_groups_v4-name-unique-constraint                                                b_FRbLWJQfqXXxyTdcU2cQ 1 1       1      0     7kb   3.5kb
green open .ent-search-actastic-crawler_crawl_requests_v4                                                                               kaUWb7YlTEeFH-Gcpz50qA 1 1       0      0    416b    208b
green open .ent-search-api-ecs-ilm-logs-production-2022.03.09-000016                                                                    EKZZOtqOR_e8pOztXsLU1g 1 1       0      0    416b    208b

Answered By – adhaamehab

Answer Checked By – Willingham (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.