第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用 Elastic 的 High Level Rest Client 獲取所有索引?

如何使用 Elastic 的 High Level Rest Client 獲取所有索引?

慕森王 2021-08-04 16:47:29
我想要一種很好、快速和簡(jiǎn)單的方法來(lái)使用他們的Java REST 客戶(hù)端獲取 elasticsearch 中的所有索引。我目前可以通過(guò)抓取他們的低級(jí)客戶(hù)端來(lái)做到這一點(diǎn),如下所示:public void fetchIndices() throws IOException {    List<String> indices = null;    RestClient restClient = client.getLowLevelClient();    Response response = null;    try {        response = restClient.performRequest("GET", "/_cat/indices?v");    } catch (IOException e) {        LOGGER.log(Level.WARNING, e.toString(), e);    }    InputStream inputStream = null;    if (response != null) {        try {            inputStream = response.getEntity().getContent();        } catch (IOException e) {            LOGGER.log(Level.WARNING, e.toString(), e);        }    }    if (inputStream != null) {        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);        indices = new ArrayList<>();        String line;        while ((line = bufferedReader.readLine()) != null) {            // Get tokens with no whitespace            String[] tokens = line.split("\\s+");            for (String token : tokens) {                // TODO - make the startsWith() token configurable                if (token.startsWith(SOME_TOKEN)) {                    LOGGER.log(Level.INFO, "Found elasticsearch index " + token);                    indices.add(token);                    break;                }            }        }    }    // Only update if we got data back from our REST call    if (indices != null) {        this.indices = indices;    }}基本上我只是按照他們的文檔中的建議調(diào)用/_cat/indices?v端點(diǎn)。這工作正常,但我想知道是否有更好的方法使用 Java API 來(lái)做到這一點(diǎn)。我似乎無(wú)法在他們當(dāng)前的 API 中找到方法,但想知道是否有人知道我不知道的事情。必須與s 和各種s一起工作并不一定很糟糕,但只想清理 hacky 字符串解析。InputStreamReader
查看完整描述

3 回答

?
繁星點(diǎn)點(diǎn)滴滴

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊

從 Elasticsearch 7.5.0 開(kāi)始,您可以使用以下內(nèi)容來(lái)檢索所有索引:

    GetIndexRequest request = new GetIndexRequest("*");
    GetIndexResponse response = client.indices().get(request, RequestOptions.DEFAULT);
    String[] indices = response.getIndices();


查看完整回答
反對(duì) 回復(fù) 2021-08-04
?
浮云間

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超4個(gè)贊

在 es 6.8 上,當(dāng)沒(méi)有索引時(shí)使用*or _allinGetIndexRequest會(huì)拋出 NoSuchIndexException。


我發(fā)現(xiàn)這是更安全的,沒(méi)有扔的方式:


    GetMappingsResponse response = esClient.indices().getMapping(new GetMappingsRequest().indices("*"),

            RequestOptions.DEFAULT);

    return new ArrayList<>(response.mappings().keySet());


查看完整回答
反對(duì) 回復(fù) 2021-08-04
  • 3 回答
  • 0 關(guān)注
  • 679 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)