# How to loop the hit result and compare the value for each from query result?

**URL:** <https://discuss.elastic.co/t/how-to-loop-the-hit-result-and-compare-the-value-for-each-from-query-result/161491>\
**Category:** Elasticsearch\
**Created:** [December 19, 2018, 10:30am UTC](https://discuss.elastic.co/t/how-to-loop-the-hit-result-and-compare-the-value-for-each-from-query-result/161491 "2018-12-19T10:30:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sky\_Iprd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sky_iprd/32/38984_2.png) [@Sky\_Iprd](https://discuss.elastic.co/u/Sky_Iprd)\
**Post date:** [December 19, 2018, 10:30am UTC](https://discuss.elastic.co/t/how-to-loop-the-hit-result-and-compare-the-value-for-each-from-query-result/161491/1 "2018-12-19T10:30:37Z")

</div>

Hi ,

I'm new to DSL query, I have a use case like 'find the id that DPS \> 100 and it does increasing in 2018 \<\> compare to 2017.

[DATA]  
ID DPS DATE  
5 100 2017  
5 110 2018  
1 50 2018  
1 60 2017

I try to use below query to get the 2017 result, but I have no idea how to compare and loop via the hit result that return from query. Any instruction / sample can help , please ? Thanks a lot

```
GET testing/_search
{
   "query":{
     "bool":{
      "filter":{
        "range": {
           "date" : {          
               "gte" : "now-1y/y",
               "lt" : "now/y"
           }
        }
       },
     "must" : {
       "range" : {
         "dps" : { "gte" : 100 }
       }
      },
      "boost" : 1.0
     }
  }
}
```

---

<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 16, 2019, 10:30am UTC](https://discuss.elastic.co/t/how-to-loop-the-hit-result-and-compare-the-value-for-each-from-query-result/161491/2 "2019-01-16T10:30:41Z")

</div>

Closed on January 16, 2019, 10:30am UTC

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