关于 Elasticsearch Nest:Elasticsearch Nest – 查询别名

Elasticsearch Nest - Querying Aliases

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

1
2
3
4
5
6
7
{
  "ntdev-events017-v1": {
     "aliases": {
        "ntdev-events017": {}
      }
   }
}

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


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

看看这个例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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();