我需要列出所有索引并输入Elasticsearch。
基本上,我使用_client.stats().Indices
获取索引,并使用foreach
排除索引列表进行过滤。
代码如:
public Dictionary<string, Stats> AllIndexes()
{
_client = new ElasticClient(setting);
var result = _client.Stats();
var allIndex = result.Indices;
var excludedIndexList = ExcludedIndexList();
foreach (var index in excludedIndexList)
{
if (allIndex.ContainsKey(index)) allIndex.Remove(index);
}
return allIndex;
}
这是从Elasticsearch列出所有索引的正确方法,还是有更好的方法。
这是有效的,一种略显性感的写作方式将使用.Except()
对result.Indices。
另一条路线是使用.CatIndices()
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cat-indices.html
代码Assembly Nest, Version=6.0.0.0
如下
var result = await _client.GetIndexAsync(null, c => c
.AllIndices()
);
你会得到result.Indices.Keys
字符串列表中的结果