The following is sample Java program to get the list of indices in an Elasticsearch instance.
Sample Program:
package com.report.test; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; public class SampleProgram{ public static void main(String[] args) { String hostname = "localhost"; String clusterName = "elasticsearch"; Settings settings = ImmutableSettings.settingsBuilder().put("client.transport.sniff", true).put("cluster.name", clusterName).build(); Client esclient = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(hostname, 9300)); String[] indexList = esclient.admin().cluster().prepareState().execute().actionGet().getState().getMetaData().concreteAllIndices(); System.out.println("Index List:"); for (String index : indexList) { System.out.println(index); } } }
Sample Output:
Index List: student employee