当我们查询时会遇到一些按照月份做索引的情况,要用到这些索引,得根据前缀来查这些索引
话不多说,直接上代码
public class IndexUtils {
public static String[] show(String index) {//参数写自己索引的前缀
TransportClient client = ESUtils.getClientForPool();
GetIndexResponse response = client.admin().indices().prepareGetIndex().execute().actionGet();
String[] indices = response.getIndices();
List<String> list = new ArrayList<>();
for (String indice : indices) {
if (indice.startsWith(index)) {
list.add(indice);
}
}
String[] str = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
str[i] = list.get(i);
}
return str;
}
}