Elasticsearch find all indexes using the Java client
最近在项目中用到了elasticsearch7.0,其中有一个方法需要记录一下:
需要查询es中的所有index名:
/**
* <获取所有index名字>
*
* @return 结果
* @throws
*/
public Set getAllIndices()
{
try
{
InputStream inputStream = restHighLevelClient.getLowLevelClient()
.performRequest(new Request("GET", "/_cat/indices?h=i")).getEntity().getContent();
List<String> indexes = new BufferedReader(new InputStreamReader(inputStream))
.lines().collect(Collectors.toList());
return new HashSet(indexes);
}
catch (IOException e)
{
LOGGER.error("error", e);
return null;
}
}
还没有评论,来说两句吧...