# Using Serial Differencing Aggregation in .NET

**URL:** <https://discuss.elastic.co/t/using-serial-differencing-aggregation-in-net/96402>\
**Category:** Elasticsearch\
**Created:** [August 9, 2017, 8:59am UTC](https://discuss.elastic.co/t/using-serial-differencing-aggregation-in-net/96402 "2017-08-09T08:59:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ximenling20](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ximenling20/32/20177_2.png) [@ximenling20](https://discuss.elastic.co/u/ximenling20)\
**Post date:** [August 9, 2017, 8:59am UTC](https://discuss.elastic.co/t/using-serial-differencing-aggregation-in-net/96402/1 "2017-08-09T08:59:08Z")

</div>

I'm tring to use [Serial Differencing Aggregation](https://www.elastic.co/guide/en/elasticsearch/client/net-api/5.x/serial-differencing-aggregation-usage.html#serial-differencing-aggregation-usage) in my C# application.

The function was working properly. However, I found there is no instruction to [handle the results](https://www.elastic.co/guide/en/elasticsearch/client/net-api/5.x/serial-differencing-aggregation-usage.html#_handling_responses_72) of Serial Differencing, but only for Sum Aggregation.

Is there anyone who had experience on calling the Serial Differencing results?

Thanks

---

<div class="post-metadata">

**Author:** ![ximenling20](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ximenling20/32/20177_2.png) [@ximenling20](https://discuss.elastic.co/u/ximenling20)\
**Post date:** [August 9, 2017, 10:54am UTC](https://discuss.elastic.co/t/using-serial-differencing-aggregation-in-net/96402/2 "2017-08-09T10:54:14Z")

</div>

Sovled by using:  
`Dictionary.FirstOrDefault()`

For example:  
`var difference = item.Aggregations.FirstOrDefault(x => x.Key == "serial_diff").Value`

And get the value by:  
`((Nest.ValueAggregate)difference).Value`

---

<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 9, 2017, 12:48pm UTC](https://discuss.elastic.co/t/using-serial-differencing-aggregation-in-net/96402/3 "2017-08-09T12:48:56Z")

</div>

Hey @ximenling20, the AggregationsHelper is missing a method for `SerialDifferencing()`; I'll add one now.

In the meantime, you can get the value as you have done 👍 You could also get it with

```
if (item.Aggregations.TryGetValue("serial_diff", out IAggregate aggregate))
{
    var serialDifferencingAggregate = (ValueAggregate) aggregate;
}
```

---

<div class="post-metadata">

**Author:** ![ximenling20](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ximenling20/32/20177_2.png) [@ximenling20](https://discuss.elastic.co/u/ximenling20)\
**Post date:** [August 9, 2017, 1:57pm UTC](https://discuss.elastic.co/t/using-serial-differencing-aggregation-in-net/96402/4 "2017-08-09T13:57:05Z")

</div>

Hey @forloop, thanks for your quick response and the nice alternative.

---

<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 6, 2017, 1:59pm UTC](https://discuss.elastic.co/t/using-serial-differencing-aggregation-in-net/96402/5 "2017-09-06T13:59:40Z")

</div>

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