1

I am in the process of migrating an app from the TransportClient to the RestHighLevelClient. Right now I have the following method for getting the index metadata:

public IndexMetaData getIndexMetaData(String indexAlias) {
    ClusterState state = transportClient.admin().cluster().prepareState()
                             .setIndices(new String[]{indexAlias})
                             .execute()
                             .actionGet()
                             .getState();
    Set<String> indices = getIndicesByAlias(indexAlias);
    if (indices.size() > 0) {
        return state.metaData().index(indices.iterator().next());
    }
    else {
        return null;
    }
}

Based on https://github.com/elastic/elasticsearch/issues/27205, the RestHighLevelClient does not have support for getting the cluster state.

How can I replace the above method by using the RestHighLevelClient?

1 Answers1

0

If I understand that correctly, you have an alias and want to get all the indices behind it? That should be doable with the GetAliasesRequest.

Try something like this:

GetAliasesResponse getAliasResponse =
   client.indices().getAlias(new GetAliasesRequest("alias"),
                             RequestOptions.DEFAULT);
getAliasResponse.getAliases().keySet(); //key has the indices, value the aliases

PS: You might want to add a check for existsAlias().

xeraa
  • 10,456
  • 3
  • 33
  • 66
  • I want to get the `IndexMetaData`, not the index alias, for a specific index. Is there any way to achieve this using `RestHighLevelClient`? – Alexandru Cojocaru Sep 01 '20 at 09:35
  • I don't think that's supported right now. But what are you trying to do in the end? The alternative is to fall back to the low level REST client, but you'll need to manually work with the response then. – xeraa Sep 01 '20 at 12:47
  • That method is part of a library that is being used by other components, so I'm trying to keep its signature intact to not affect its callers. To be honest, I don't understand why the Elasticsearch team is pushing the `RestHighLevelClient` if it does not provide all the features of the old client. This and the type existence checks are 2 examples of such missing APIs. – Alexandru Cojocaru Sep 01 '20 at 14:27
  • You mean for `_type`? Because that feature has been removed in 7.0. And there should be few use-cases where you'd have to fall down to the cluster state. That's more of a cleanup with the escape hatch through the low level REST client. – xeraa Sep 01 '20 at 18:53