Get List of indices using Java Rest API


(Roopesh Kumar) #1

Hi,
I am using Java REST APIs 5.1.1 for elasticsearch. I need to get the list of indexes on successful connection to elasticsearch using host, port, username, password.
I am not able to get a list of available indexes.

Please help.


(Andrew Kroh) #2

What have you tried? You can get a list of all indices with:

curl -XGET "http://localhost:9200/_aliases"


(Roopesh Kumar) #3

Hi @andrewkroh,

Sorry, it is my bad. Actually I got this command earlier. But I don't know how to call this using java rest APIs given.
I am new in Java development. How to execute this from RestClient, or what is the way to call this and get result in java.

Thanks


(Andrew Kroh) #4

Have you seen the examples here?

Response response = restClient.performRequest("GET", "/_aliases",
        Collections.singletonMap("pretty", "true"));
System.out.println(EntityUtils.toString(response.getEntity()));

Then you need to unmarshal the response.


(Roopesh Kumar) #5

Thanks @andrewkroh,
It worked.
Though I have been through the example requests page, but I think I missed that EntityUtils thing.

Thanks again.
:slight_smile:


(system) #6

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