Using ES rest client, How to get List of all unique index based on some search criterion. Below code gives my all index names but duplicate ones too. Please help.
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());
}
Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.
Or use markdown style like:
```
CODE
```
There's a live preview panel for exactly this reasons.
Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.
Thanks @dadoonet. . I formatted the code.I tried to apply the aggregation on_index field. But still I am getting duplicate index names. I am using 6.2.1 High Level Rest Client. Could you please suggest me right code snippet for this aggregation case.Thanks In advance.
Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.
Please share what you got and your code.
@dadoonet I am able to get the result while hitting directly to elasticsearch using but i am not able to find corresponding java methods in high level rest client latest version.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.