使用ES rest客户端,如何根据某些搜索条件获取所有唯一索引名称的列表。下面的代码给出了我的所有索引名称,但也是重复的。请帮忙。
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.matchQuery("indexMetadata.user","95103"));
boolQueryBuilder.must(QueryBuilders.matchQuery("indexMetadata.indexLevel","LOCAL"));
sourceBuilder.query(boolQueryBuilder);
SearchRequest searchRequest = new SearchRequest();
String[] includeFields = new String[]{"hits.hits._index"};
String[] excludeFields = new String[]{};
sourceBuilder.fetchSource(includeFields, excludeFields);
searchRequest.source(sourceBuilder);
SearchResponse searchResponse = client.search(searchRequest);
SearchHits hits = searchResponse.getHits();
SearchHit[] searchHits = hits.getHits();
for (SearchHit hit : searchHits) {
System.out.println(hit.getIndex());
}