# How to compare data for 1 hr to the data for the same 1 hour 7 days ago

**URL:** <https://discuss.elastic.co/t/how-to-compare-data-for-1-hr-to-the-data-for-the-same-1-hour-7-days-ago/193313>\
**Category:** Elasticsearch\
**Created:** [August 1, 2019, 12:04pm UTC](https://discuss.elastic.co/t/how-to-compare-data-for-1-hr-to-the-data-for-the-same-1-hour-7-days-ago/193313 "2019-08-01T12:04:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kalyani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kalyani/32/40717_2.png) [@kalyani](https://discuss.elastic.co/u/kalyani)\
**Post date:** [August 1, 2019, 12:04pm UTC](https://discuss.elastic.co/t/how-to-compare-data-for-1-hr-to-the-data-for-the-same-1-hour-7-days-ago/193313/1 "2019-08-01T12:04:10Z")

</div>

Hello,  
I have a set of data from an elastic search index for a period of 1 hour today.  
I want to compare that count with the data for the same 1 hrs but 7days ago.  
And then calculate the percentage change.  
Please suggest ways!  
Thanks.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 1, 2019, 12:23pm UTC](https://discuss.elastic.co/t/how-to-compare-data-for-1-hr-to-the-data-for-the-same-1-hour-7-days-ago/193313/2 "2019-08-01T12:23:51Z")

</div>

Hey,

there are a couple of solutions to this. I am not sure what you mean with `count` here. Is it just the number of documents or something else? You could execute a single query that searches for both time spans (and your other criteria) and then use a [filters aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/7.2/search-aggregations-bucket-filters-aggregation.html) for each timespan - you could even go one step further and do the final calculation using a pipeline aggregation. You could also just execute two queries and calculate the difference on the client side.

Do whatever is the easiest for you and gives you the right answer.

--Alex

---

<div class="post-metadata">

**Author:** ![kalyani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kalyani/32/40717_2.png) [@kalyani](https://discuss.elastic.co/u/kalyani)\
**Post date:** [August 5, 2019, 8:56am UTC](https://discuss.elastic.co/t/how-to-compare-data-for-1-hr-to-the-data-for-the-same-1-hour-7-days-ago/193313/3 "2019-08-05T08:56:51Z")

</div>

Hello @spinscale , Thanks for the quick reply.  
Yes, the count I mentioned is just the number of documents.  
Now the challenge I am facing while using filter aggregation is that I am unable to add filter for "the current 1 hour data 7 days ago " .  
Tried "now -7d" .It just gives me the data for 7 days.

Can you please help me out with the filter query?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 5, 2019, 9:40am UTC](https://discuss.elastic.co/t/how-to-compare-data-for-1-hr-to-the-data-for-the-same-1-hour-7-days-ago/193313/4 "2019-08-05T09:40:45Z")

</div>

sorry, not sure I get what the problem is? If you were able to specify the same in query you can also specify it in a filter.

---

<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 2, 2019, 9:40am UTC](https://discuss.elastic.co/t/how-to-compare-data-for-1-hr-to-the-data-for-the-same-1-hour-7-days-ago/193313/5 "2019-09-02T09:40:49Z")

</div>

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