Having issues translating query dsl to NEST

I am using the nuget Nest(7.17.4) and am particular stucked at translating 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 there is an effective way to perform the translation? any tips, suggestions, advices would be very much appreciated. Thanks!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.