public override async Task <IndexStats> GetStatsAsync(CancellationToken cancellationToken) { // The request. IIndicesStatsRequest request = new IndicesStatsRequest(Indices.Index <T>()); // Get the response. IIndicesStatsResponse response = await ElasticClient .IndicesStatsAsync(request, cancellationToken).ConfigureAwait(false); // If failed, throw. response.ThrowIfError(); // Map and return. return(response.Indices[Name].ToElasticsearchIndexStats()); }
private void PopulateIndexDescription(ElasticAccess.IndexDefinition indexDef, IIndicesStatsResponse indexStats) { string description = string.Empty; // get names and aliases if (indexDef.Index != null) { var index = indexDef.Index.Indices.FirstOrDefault(); var indexState = index.Value; description = index.Key + Environment.NewLine + Environment.NewLine; if (indexState.Aliases.Count > 0) { description += "Aliased by: " + indexState.Aliases.First().Key.Name + Environment.NewLine + Environment.NewLine; } } // settings if (indexDef.Settings != null) { description += "Replicas: " + indexDef.Settings.NumberOfReplicas + Environment.NewLine; description += "Shards: " + indexDef.Settings.NumberOfShards + Environment.NewLine; const string CREATED_ON = "index.creation_date"; if (indexDef.Settings.ContainsKey(CREATED_ON)) { double milliseconds; if (double.TryParse(indexDef.Settings[CREATED_ON].ToString(), out milliseconds)) { description += "Created On: " + Utilities.UnixTimeStampToDateTime(milliseconds).ToString() + Environment.NewLine; } } } // fields string fields = string.Empty; if (indexDef.Mappings != null) { foreach (var field in indexDef.Mappings.Values.First().Properties) { fields += $"{field.Value.Name.Name}, {field.Value.Type}{Environment.NewLine}"; Debug.WriteLine(field.Value.Name); } description += Environment.NewLine + "Fields" + Environment.NewLine; description += fields + Environment.NewLine; } // stats description += Environment.NewLine + "Statistics" + Environment.NewLine; if (indexStats?.Stats?.Total?.Store != null) { description += "Size: " + Utilities.SizeSuffix((long)indexStats.Stats.Total.Store.SizeInBytes) + Environment.NewLine; } if (indexStats?.Stats?.Total?.Documents != null) { description += "Documents: " + $"{indexStats.Stats.Total.Documents.Count:N0}" + Environment.NewLine; description += "Deleted: " + $"{indexStats.Stats.Total.Documents.Deleted:N0}" + Environment.NewLine; } textEditor.Editor.Text = description; }