lucene - ElasticSeach JAVA API to find aliases given index -
how find aliases given index in elasticsearch using java?
by using rest api pretty easy
https://www.elastic.co/guide/en/elasticsearch/reference/1.x/indices-aliases.html#alias-retrieving
but unable find reference on how via java api
while working elasticsearch, ran issue needed list of aliases based on provided index.
while getting list of aliases pretty straightforward:
client.admin().cluster() .preparestate().execute() .actionget().getstate() .getmetadata().aliases();
i struggled find easy way able aliases given index without having iterate through first.
my first implementation looked this:
immutableopenmap<string, immutableopenmap<string, aliasmetadata>> aliases = client.admin().cluster() .preparestate().execute() .actionget().getstate() .getmetadata().aliases(); (objectcursor<string> key: aliases.keys()) { immutableopenmap<string, aliasmetadata> indextoaliasesmap = client.admin().cluster() .state(requests.clusterstaterequest()) .actionget().getstate() .getmetadata().aliases().get(key.value); if(indextoaliasesmap != null && !indextoaliasesmap.isempty()){ string index= indextoaliasesmap.keys().iterator().next().value; string alias = indextoaliasesmap.values().iterator().next().value.alias(); } }
i did not it... , after poking around, able idea on how more efficiently looking @ restgetindicesaliasesaction (package org.elasticsearch.rest.action.admin.indices.alias.get)
this end with:
clusterstaterequest clusterstaterequest = requests.clusterstaterequest() .routingtable(false) .nodes(false) .indices("your_index_name_goes_here"); objectlookupcontainer<string> setaliases= client .admin().cluster().state(clusterstaterequest) .actionget().getstate().getmetadata() .aliases().keys();
you able find aliases index specified in setaliases
hope helps someone!
Comments
Post a Comment