How to describe this aggregation using the Nest .NET Library?

I have an aggregation that also has a filter and I am having trouble composing it with the .NET Nest Library:

{
  "aggs": {
    "positive_lat": {
      "filter": {
        "bool": { 
          "must_not": [
            {
              "term": {
                "latitude": 0
              }
            }
          ]
        }
      }, 
      "aggs" : {
        "min_lat": {
          "min": {
             "field": "latitude"
          }
        }
      }
    }
  }
}

How does one do something like that? Is it possible?

Yep, it's possible:

var client = new ElasticClient();

// use your document type instead of object
var searchResponse = client.Search<object>(s => s
    .Aggregations(a => a
        .Filter("positive_lat", f => f
            .Filter(q => q
                .Bool(b => b
                    .MustNot(mn => mn
                        .Term("latitude", 0)
                    )
                )
            )
            .Aggregations(aa => aa
                .Min("min_lat", m => m
                    .Field("latitude")
                )
            )
        )
    
    )
);

// do something with min latitude
var minLatitude = searchResponse.Aggregations.Filter("positive_lat").Min("min_lat").Value;

Take a look at the Writing Aggregations documentation, as well as the usage examples for aggregations.

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