# Calculate on nested field, got wrong result , any advice will be appreciated

**URL:** <https://discuss.elastic.co/t/calculate-on-nested-field-got-wrong-result-any-advice-will-be-appreciated/124985>\
**Category:** Elasticsearch\
**Created:** [March 21, 2018, 12:42pm UTC](https://discuss.elastic.co/t/calculate-on-nested-field-got-wrong-result-any-advice-will-be-appreciated/124985 "2018-03-21T12:42:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![small-tomorrow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/small-tomorrow/32/13319_2.png) [@small-tomorrow](https://discuss.elastic.co/u/small-tomorrow)\
**Post date:** [March 21, 2018, 12:42pm UTC](https://discuss.elastic.co/t/calculate-on-nested-field-got-wrong-result-any-advice-will-be-appreciated/124985/1 "2018-03-21T12:42:45Z")

</div>

**with query conditions, I filtered out only one doc, part of the doc \_source is :**

> ```
> "_source": {
> "event": [
> {
> "time": 1520252057459,
> "duration": 1876,
> "speed": 0,
> "event_name": "firstBufferingEnd",
> "detail": "",
> "cdn_ip": ""
> },
> {
> "time": 1520252060460,
> "duration": 0,
> "speed": 207445,
> "event_name": "networkSpeed",
> "detail": "",
> "cdn_ip": ""
> },
> {
> "time": 1520252062460,
> "duration": 0,
> "speed": 96871,
> "event_name": "networkSpeed",
> "detail": "",
> "cdn_ip": ""
> },
> {
> "time": 1520252064460,
> "duration": 0,
> "speed": 0,
> "event_name": "networkSpeed",
> "detail": "",
> "cdn_ip": ""
> },
> 
> ```

**query body is as follow , I got the avg value of speed, but the value is obvious wrong, how can I exclude out those dirty events such as the _"firstBufferingEnd"_**?

> ```
> {
> "query": {
> "nested": {
> "path": "event",
> "query": {
> "bool": {
> "must": [
> {
> "range": {
> "event.speed": {
> "gt":10000000
> }
> }
> },
> {
> "terms": {
> "event.event_name": [
> "networkSpeedReport",
> "networkSpeed"
> ]
> }
> }
> ]
> }
> }
> }
> },
> "aggs":{
> "gg":{
> "nested": {
> "path":"event"
> },
> "aggs":{
> "gg":{
> "avg":{
> "field":"event.speed"
> }
> }
> }
> }
> }
> }
> 
> ```

pictures are :

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/8/880e419684502c91981dd1ec7b9cdd1ab7eb0b85.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/9/99c435450b0305a392ab4a71bbff43e54e9fcb9b.png)

---

<div class="post-metadata">

**Author:** ![small-tomorrow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/small-tomorrow/32/13319_2.png) [@small-tomorrow](https://discuss.elastic.co/u/small-tomorrow)\
**Post date:** [March 22, 2018, 3:42am UTC](https://discuss.elastic.co/t/calculate-on-nested-field-got-wrong-result-any-advice-will-be-appreciated/124985/2 "2018-03-22T03:42:17Z")

</div>

@Allwyn sorry to disturb , I have been stuck at here for days , (can not found anything from google and official doc )

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 22, 2018, 7:37am UTC](https://discuss.elastic.co/t/calculate-on-nested-field-got-wrong-result-any-advice-will-be-appreciated/124985/3 "2018-03-22T07:37:23Z")

</div>

Read [this](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and specifically the "Also be patient" part.

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an answer.

---

<div class="post-metadata">

**Author:** ![small-tomorrow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/small-tomorrow/32/13319_2.png) [@small-tomorrow](https://discuss.elastic.co/u/small-tomorrow)\
**Post date:** [March 23, 2018, 8:05am UTC](https://discuss.elastic.co/t/calculate-on-nested-field-got-wrong-result-any-advice-will-be-appreciated/124985/4 "2018-03-23T08:05:31Z")

</div>

OK， thanks for your patience

---

<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:** [April 20, 2018, 8:05am UTC](https://discuss.elastic.co/t/calculate-on-nested-field-got-wrong-result-any-advice-will-be-appreciated/124985/5 "2018-04-20T08:05:37Z")

</div>

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