[Aggregation Query] Recreate kibana dashboards in asp.net core

Hi all, I am looking for ways to recreate my kibana dashboards on my own website (wanna do a little more one the visuals) , thus I have to get data from elasticsearch and query them and then visualize them.

I am using the nuget Nest(7.17.4) and am particular stucked at the fluent query dsl ...I thought there would be some syntax or any method I can utilize in Nest to simply paste the request queries (from inspect) for each dashboard items and then I can focus on my visualization, however that is not the case. I can use

.Query(q => q
                    .Raw(json_str.ToString())
                    )

But the aggregation and the rest of the request has to be done with the Nest language (It's called Fluent DSL I think?) And since I will have to scroll to get all the data, but in some cases I don't know where to put my scroll.. I still never get the same data as the dashboard shown on my kibana nor do I know how to get the query right.

For example:

There's this request I got from inspecting a table in my dashboard (count my_record occurence and get the top five) :

{
  "aggs": {
    "2": {
      "terms": {
        "field": "my_record.keyword",
        "order": {
          "_count": "desc"
        },
        "size": 5
      }
    }
  },
  "size": 0,
  "fields": [
    {
      "field": "SystemTime",
      "format": "date_time"
    }
  ],
  "script_fields": {},
  "stored_fields": [
    "*"
  ],
  "runtime_mappings": {},
  "_source": {
    "excludes": []
  },
  "query": {
   .........my raw query in json file.......
  }
}

In my .net application I have sth like this:

 var json_str = System.IO.File.ReadAllText(@"my_json_file_location");
                results = _client.Search<Records>(s => s
                    .Aggregations(a => a
                      .Terms("2", t => t
                          .Field("my_record.keyword")
                          .Order(o => o.CountDescending())
                          .Size(5)
                          )
                     )
                    .Size(0)
                    .Fields(f => f
                        .Field("SystemTime")
                    .StoredFields("*")
                    .Query(q => q
                    .Raw(json_str.ToString())
                    )
                );

I wonder if anyone has done anything similiar, any tips, suggestions, advices would be very much appreciated. Thanks!

Just for future reference, you can click the 3 little dots at the bottom of the post and then edit it :slight_smile: