How to find all unique Index names for a matching document


(riki) #1

Hi,

I am keeping log file information in the Indices. The Indices are created every 6 hours. Each Indices has a field which has a logical name based on the Collection Source. These details are kept for historical analysis, so the data are kept for very long time and older Indices are used only for read purpose.

I am trying to delete the documents based on the Collection Source but I see that Disk Space is not reclaimed. To reclaiming Disk Space, I am trying to use 'only_expunge_deletes' explicitly. On my test environment, I tried using 'only_expunge_deletes' on all Indices and saw that more than 50% of Disk Space freed up.

Now I want to delete and execute 'only_expunge_deletes' API only on the Indices which matches a criteria. So I am trying to find out which all Indices has the data.

I am trying to make use of below API and this returns me the Index names but it does not return unique index names (which is expected).

BoolQueryBuilder query = QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("CN", "mc_127.0.0.1"));
query.filter(QueryBuilders.boolQuery().must(QueryBuilders.existsQuery("CN")));
SearchRequestBuilder builder = client.prepareSearch();
SearchResponse res = builder.setQuery(query).setFrom(0).setSize(1000).execute().actionGet();
if (res != null) {
	SearchHit[] hits = res.getHits().getHits();
	for (SearchHit hit : hits) {
		System.out.println(hit.getIndex());
	}
}

Is there a way to find out unique index names matching a criteria?


(Fanfan) #2

This may give some advice https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html


(riki) #3

Thanks for sharing the link.

But I am not sure if I can find the unique Index names based on a Field Value.


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.