Elasticsearch find all indexes using the Java client

Dear 丶 2021-11-26 23:04 363阅读 0赞

最近在项目中用到了elasticsearch7.0,其中有一个方法需要记录一下:

需要查询es中的所有index名:

  1. /**
  2. * <获取所有index名字>
  3. *
  4. * @return 结果
  5. * @throws
  6. */
  7. public Set getAllIndices()
  8. {
  9. try
  10. {
  11. InputStream inputStream = restHighLevelClient.getLowLevelClient()
  12. .performRequest(new Request("GET", "/_cat/indices?h=i")).getEntity().getContent();
  13. List<String> indexes = new BufferedReader(new InputStreamReader(inputStream))
  14. .lines().collect(Collectors.toList());
  15. return new HashSet(indexes);
  16. }
  17. catch (IOException e)
  18. {
  19. LOGGER.error("error", e);
  20. return null;
  21. }
  22. }

发表评论

表情:
评论列表 (有 0 条评论,363人围观)

还没有评论,来说两句吧...

相关阅读