![](/img/trans.png)
[英]Elasticsearch Java Rest Client: how to get the list of all indices
[英]How to get a List of Indices from ElasticSearch using Jest
我正在尝试使用 Jest 检索索引列表,但我只是:
Stats statistics = new Stats.Builder().build();
result = client.execute(statistics);
如何从结果中检索索引列表? 我必须使用 Stats 以外的其他东西吗? 如果有人可以向我展示 Jest 的详细文档,这也会有所帮助。 基础知识确实有据可查,但是对于不同类型的构建器,我现在真的很迷茫。
Get Aliases 将为您提供节点上索引的所有别名。
只需将浏览器导航到以下 URL,即可获取 ElasticSearch 集群上可用的索引。
HTTP:// elasticsearch.company.com / _aliases
这将在 JSON 中返回一组索引及其别名。 下面是一个例子:
{
"compute-devzone1": { },
"compute-den2": { },
"compute-den1": { },
...
}
要使用 Jest 获取索引列表,请使用此代码...
HttpClientConfig config;
JestClientFactory factory;
JestClient client;
GetAliases aliases;
JestResult result;
String json;
config = new HttpClientConfig.
Builder("http://elasticsearch.company.com").
build();
aliases = new GetAliases.
Builder().
build();
factory = new JestClientFactory();
factory.setHttpClientConfig(config);
client = factory.getObject();
result = client.execute(aliases);
json = result.getJsonString();
使用您最喜欢的 JSON 处理器从json
提取索引。
用:
JestResult result = elasticSearchClient.execute(new Cat.IndicesBuilder().build());
这将返回一个 JSON 响应,就像curl -XGET "localhost:9200/_cat/indices?format=json"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.