# Multiple aggregations in NEST C#

**URL:** <https://discuss.elastic.co/t/multiple-aggregations-in-nest-c/213277>\
**Category:** Elasticsearch\
**Created:** [December 29, 2019, 9:10am UTC](https://discuss.elastic.co/t/multiple-aggregations-in-nest-c/213277 "2019-12-29T09:10:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam.cook](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sam.cook](https://discuss.elastic.co/u/sam.cook)\
**Post date:** [December 29, 2019, 9:10am UTC](https://discuss.elastic.co/t/multiple-aggregations-in-nest-c/213277/1 "2019-12-29T09:10:07Z")

</div>

I am trying to translate an ElasticSearch query in NEST C# code.  
The query I need to searches for documents with certain values on field1 and field2 and that has the insertedon DateTime value between a selected range. After that, it groups the results by field3 and sums a field duration.

I paste the query described above:

```auto
{
"aggs": {
	"filtered": {
		"filter": {
			"bool": {
				"must": [
						{ "term": { "line": "01" } },
						{ "term": { "machine": "01" } }, 
						{ "term": { "stationtype": "01" } },  
						{ "term": { "station": "01" } }, 
						{ 
							"range": {
								"insertedon": {
									"gte": "2019-11-10", 
									"lt": "2019-11-11"
								}
							}
						}
					]
				}
			},
			"aggs": {
				"by_station": {
					"terms": {
						"field": "idstate"
					},
					"aggs": {
						"sum_duration": {
							"sum": {
								"field": "duration"
							}
						}
					}
				}
			}
		}
	}
}

```

---

<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:** [January 26, 2020, 9:10am UTC](https://discuss.elastic.co/t/multiple-aggregations-in-nest-c/213277/2 "2020-01-26T09:10:16Z")

</div>

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