Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch Nest - Querying Aliases

Does the Elasticsearch NEST API expose access to /{index}/{_aliases}/*? I am trying to get a list of indexes mapped to a given alias and I cannot seem to find an appropriate method.

{
   "ntdev-events017-v1": {
      "aliases": {
         "ntdev-events017": {}
      }
   }
}

http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html

like image 747
Nathan Taylor Avatar asked Apr 10 '15 21:04

Nathan Taylor


1 Answers

You can use GetAlias method on ElasticClient.

Take a look on this example:

var indexName = "sampleindex";

var uri = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(uri).SetDefaultIndex(indexName).EnableTrace();
var client = new ElasticClient(settings);

client.CreateIndex(descriptor => descriptor.Index(indexName));

var putAliasResponse = client.PutAlias(descriptor => descriptor
    .Index(indexName).Name("alias1"));
var putAliasResponse2 = client.PutAlias(descriptor => descriptor
    .Index(indexName).Name("alias2"));

var aliasesForIndex = client.GetAlias(descriptor => descriptor
        .Index(indexName))
        .Indices[indexName]
        .Select(x => x.Name).ToList();
var indexesMappedToAlias = client.GetAlias(descriptor => descriptor.Alias("alias2"))
                .Indices.Select(x => x.Key).ToList();
like image 118
Rob Avatar answered Sep 28 '22 19:09

Rob