I need to list all the indexes and types in Elasticsearch.
Basically I use _client.stats().Indices
to acquire the indexes, and filter using foreach
excluded index list like this:
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;
}
Is this right way to do to list all the indexes from Elasticsearch or is there a better way?
GetIndexAsync
is removed from Assembly Nest, Version=7.0.0.0
from Version=7.0.0.0
you can use this :
var result = await _client.Indices.GetAsync(new GetIndexRequest(Indices.All));
This works, a slightly sexier way of writing it would be using .Except()
on result.Indices.
Another route would be by using .CatIndices()
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cat-indices.html
Code Assembly Nest, Version=6.0.0.0
as below
var result = await _client.GetIndexAsync(null, c => c
.AllIndices()
);
you will get result in result.Indices.Keys
string list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With