Multiple aggregations in NEST C#

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:

{
"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"
							}
						}
					}
				}
			}
		}
	}
}

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