I have index with fields like deviceId
, deviceName
, osName
etc. I need to get top N osNames
with count
. For this I prepare query like this:
var response = await this.esClient.SearchAsync<object>(s =>
s.Index(Constants.DevicesIndexName)
.Size(0)
.Aggregations(a =>
a.Terms("top_os", t =>
t.Field("osName")
.Size(7))));
var aggregations = response.Aggregations.GetStringTerms("top_os");
var series = aggregations.Buckets.Select(value => new DataSeries { Name = value.Key.ToString(), Data = [(int)value.DocCount] }).ToList();
I am thinking that here can be a better or at least improved way to get this data.
Should I pass some concrete type into .SearchAsync<T>
method that represent structure of index? Should I receive terms in other type?
Nuget package used: Elastic.Clients.Elasticsearch 8.12.0