# Elastic Search Aggregations

**URL:** <https://discuss.elastic.co/t/elastic-search-aggregations/262009>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [January 23, 2021, 10:37pm UTC](https://discuss.elastic.co/t/elastic-search-aggregations/262009 "2021-01-23T22:37:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srini12](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Srini12](https://discuss.elastic.co/u/Srini12)\
**Post date:** [January 23, 2021, 10:37pm UTC](https://discuss.elastic.co/t/elastic-search-aggregations/262009/1 "2021-01-23T22:37:38Z")

</div>

Hi  
I am trying to build small app with facets, I am using NEST to get aggregations.  
When I execute the aggregations query using cURL iam getting expected results:  
my cURL is

```auto
POST product/_search
{
  "aggs": {
    "group_by_brand": {
      "terms": { "field": "brand.keyword" }
    }
  }
}

"aggregations" : {
    "group_by_brand" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "hokey",
          "doc_count" : 4
        },
        {
          "key" : "ubest",
          "doc_count" : 4
        },
        {
          "key" : "beert",
          "doc_count" : 2
        }
      ]
    }

```

However, I am unable to retrieve the results using NEST.

```auto
var node = new Uri("http://localhost:9200");
            var settings = new ConnectionSettings( node).DefaultIndex("product");
            var client = new ElasticClient(settings);

            //create a terms query
            var query = new TermsQuery
                {
                IsVerbatim = true, Field = "brand", Terms = new string[] { "25" },
                };

            var fields = new TestProduct();
            string[] Fields = new[]
                     {
                        nameof(fields.brand),
                        //nameof(fields.color)
                    };
            var aggregations = new Dictionary<string, IAggregationContainer>();
            foreach (string sField in Fields)
                {
                var termsAggregation = new TermsAggregation(sField)
                    {
                    Field = sField, //"brand.keyword" ,
                    Missing ="N/A"
                    };
                aggregations.Add(sField, new AggregationContainer { Terms = termsAggregation });
                }
            //create the search request
            var searchRequest = new SearchRequest
                {
                Query = query,
                From = 0,
                Size = 100,
                Aggregations = aggregations
                };

            var result = client.SearchAsync<AggregationDTO>(searchRequest).Result;

```

I am getting Valid Nest response but however aggregations values are null.

Can some one advise me, what I am missing.

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [January 25, 2021, 6:01pm UTC](https://discuss.elastic.co/t/elastic-search-aggregations/262009/2 "2021-01-25T18:01:20Z")

</div>

> [@Srini12](#):
>
> `"field": "brand.keyword"`

Just making sure ... first query has ""field": "brand.keyword"" whereas NEST has "fields.brand". Hope its the same field in both examples you are trying.

---

<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:** [February 22, 2021, 6:01pm UTC](https://discuss.elastic.co/t/elastic-search-aggregations/262009/3 "2021-02-22T18:01:37Z")

</div>

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