Search code examples
elasticsearchnestelasticsearch-net

Get index shard count


I need to get the number of primary shards for a particular index, in C#, using Nest (or Elastic.Net, doesn't matter). Which API call should I use?

  1. IndicesShardStores
  2. CatShards
  3. GetIndexSettings

or something else?

Is this right and the best-performing way?

var settings = client.GetIndexSettings(i => i.Index(sourceIndexName));
settings.Indices[sourceIndexName].Settings.NumberOfShards

Solution

  • If you simply want to count the number of primary shards of a given index, then GetIndexSettings() is the best option. Other options you listed return way more information than you need.