亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 golang 客戶端庫從 Elasticsearch 獲取所有索引名稱?

如何使用 golang 客戶端庫從 Elasticsearch 獲取所有索引名稱?

Go
守著星空守著你 2022-11-23 19:50:54
我在 go https://pkg.go.dev/github.com/elastic/go-elasticsearch/esapi#CatIndicesRequest中使用這個庫從 Elasticsearch 查詢。我有一些查詢示例,但我正在尋找一種 API 方法來從 Elasticsearch 集群獲取所有索引。但我無法從他們的文檔中找到我可以使用的。有誰知道獲取所有索引的最佳方法是什么?像 http api_cat/indices
查看完整描述

1 回答

?
慕妹3146593

TA貢獻1820條經驗 獲得超9個贊

這是一個工作示例:


package main


import (

    "context"

    "fmt"


    "github.com/elastic/go-elasticsearch/v7"

    "github.com/elastic/go-elasticsearch/v7/esapi"

)


func main() {


    cfg := elasticsearch.Config{

        Addresses: []string{

            "http://localhost:9243",

        },

        Username: "foo",

        Password: "bar",

    }

    es, err := elasticsearch.NewClient(cfg)

    if err != nil {

        panic(err)

    }

    res, err := esapi.CatIndicesRequest{Format: "json"}.Do(context.Background(), es)

    if err != nil {

        return

    }

    defer res.Body.Close()


    fmt.Println(res.String())

}


您可以調整CatIndicesRequest以格式化您的案例的輸出。例如,如果您使用CatIndicesRequest{Pretty: true, Human: true}. 它會返回這樣的東西:


[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


查看完整回答
反對 回復 2022-11-23
  • 1 回答
  • 0 關注
  • 357 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號