Elasticsearch Nest——查询别名

Elasticsearch Nest - Querying Aliases

Elasticsearch NEST API 是否公开对 /{index}/{_aliases}/* 的访问?我正在尝试获取映射到给定别名的索引列表,但似乎找不到合适的方法。

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

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

您可以在 ElasticClient 上使用 GetAlias 方法。

看看这个例子:

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();