How to get all the indexes and filter the indexes by using Nest in C#
10,511
Solution 1
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));
Solution 2
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
Solution 3
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
Author by
caoglish
Updated on June 08, 2022Comments
-
caoglish almost 2 years
I need to list all the indexes and types in Elasticsearch.
Basically I use
_client.stats().Indices
to acquire the indexes, and filter usingforeach
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?