cao*_*ish 6 .net c# elasticsearch nest
我需要列出 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;
}
Run Code Online (Sandbox Code Playgroud)
这是从 Elasticsearch 列出所有索引的正确方法还是有更好的方法?
GetIndexAsync
Assembly Nest, Version=7.0.0.0
从Version=7.0.0.0
你可以使用这个删除:
var result = await _client.Indices.GetAsync(new GetIndexRequest(Indices.All));
Run Code Online (Sandbox Code Playgroud)
这是可行的,这是一种稍微性感的编写方式,可以.Except()
在 result.Indices 上使用。
另一条路线是使用.CatIndices()
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cat-indices.html
归档时间: |
|
查看次数: |
9697 次 |
最近记录: |