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

**URL:** <https://discuss.elastic.co/t/how-to-describe-this-aggregation-using-the-nest-net-library/143907>\
**Category:** Elasticsearch\
**Created:** [August 10, 2018, 4:52pm UTC](https://discuss.elastic.co/t/how-to-describe-this-aggregation-using-the-nest-net-library/143907 "2018-08-10T16:52:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgelb](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@rgelb](https://discuss.elastic.co/u/rgelb)\
**Post date:** [August 10, 2018, 4:52pm UTC](https://discuss.elastic.co/t/how-to-describe-this-aggregation-using-the-nest-net-library/143907/1 "2018-08-10T16:52:26Z")

</div>

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

```auto
{
  "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?

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [August 12, 2018, 11:52pm UTC](https://discuss.elastic.co/t/how-to-describe-this-aggregation-using-the-nest-net-library/143907/2 "2018-08-12T23:52:06Z")

</div>

Yep, it's possible:

```auto
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](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/writing-aggregations.html), as well as the [usage examples for aggregations](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/reference-aggregations.html).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 9, 2018, 11:52pm UTC](https://discuss.elastic.co/t/how-to-describe-this-aggregation-using-the-nest-net-library/143907/3 "2018-09-09T23:52:07Z")

</div>

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