# Aggregation count problem

**URL:** <https://discuss.elastic.co/t/aggregation-count-problem/104976>\
**Category:** Elasticsearch\
**Created:** [October 23, 2017, 10:18pm UTC](https://discuss.elastic.co/t/aggregation-count-problem/104976 "2017-10-23T22:18:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohammed\_cherif](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@mohammed\_cherif](https://discuss.elastic.co/u/mohammed_cherif)\
**Post date:** [October 23, 2017, 10:18pm UTC](https://discuss.elastic.co/t/aggregation-count-problem/104976/1 "2017-10-23T22:18:30Z")

</div>

Hello,  
I want to display an indicator on kibana, but I can not do it. I explain the situation.  
I want to display "the total number of products whose thresholds exceeded the maximum of consumers' cuttof".  
we have a product that contains the following elements (idProduct, idConsumer, sillDate, cutoff, libProduct). the relationship between products and consumers is of type (n, n).

the formula to use is: product.stillDate-Max (product.cutoff)\> 0

example of given:

product: A1- consumer: C1

> {  
> "IdProduct": "A1",  
> "IdConsumer", "C1",  
> "SillDate": "2017-10-23T10: 00: 00Z"  
> "Cutoff": "2017-10-21T00: 00: 00Z"  
> "LibProduct", "test"  
> }

product: A1- consumer: C2

> {  
> "IdProduct": "A1",  
> "IdConsumer": "C2"  
> "SillDate": "2017-10-23T10: 00: 00Z"  
> "Cutoff": "2017-10-22T08: 00: 00Z"  
> "LibProduct": "test1"  
> }

product: A1- consumer: C3

> {  
> "IdProduct": "A1",  
> "IdConsumer": "C3"  
> "SillDate": "2017-10-23T10: 00: 00Z"  
> "Cutoff": "2017-10-23T08: 00: 00Z"  
> "LibProduct": "test2"  
> }

a product A1 is associated with 3 consumers with 3 cutoffs. the maximum cutoff for product A1 is:  
2017-10-23T08: 00: 00Z. So the number is: sum ((2017-10-23T10: 00: 00Z -2017-10-23T08: 00: 00Z)\> 0)

The question how can I do this on kibana?  
Thank you for your help and I apologize for my level in English

---

<div class="post-metadata">

**Author:** ![mohammed\_cherif](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@mohammed\_cherif](https://discuss.elastic.co/u/mohammed_cherif)\
**Post date:** [October 26, 2017, 9:43am UTC](https://discuss.elastic.co/t/aggregation-count-problem/104976/2 "2017-10-26T09:43:28Z")

</div>

Any help ?

---

<div class="post-metadata">

**Author:** ![A\_B](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/a_b/32/17104_2.png) [@A\_B](https://discuss.elastic.co/u/A_B)\
**Post date:** [October 26, 2017, 1:40pm UTC](https://discuss.elastic.co/t/aggregation-count-problem/104976/3 "2017-10-26T13:40:41Z")

</div>

As long as your dates are indexed as dates this should be possible. Kibana uses Lucine Query Syntax

See [https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-query-string-query.html#\_ranges](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-query-string-query.html#_ranges)

A search of `IdProduct: $PRODUCT_ID AND Cutoff:>$DATE` should give you the results you want. Use that query for a chart and bucket by `IdConsumer`. If I understood you correctly 🙂

-AB

---

<div class="post-metadata">

**Author:** ![mohammed\_cherif](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@mohammed\_cherif](https://discuss.elastic.co/u/mohammed_cherif)\
**Post date:** [October 26, 2017, 5:50pm UTC](https://discuss.elastic.co/t/aggregation-count-problem/104976/4 "2017-10-26T17:50:20Z")

</div>

$PRODUCT\_ID AND $DATE are the variable ?

---

<div class="post-metadata">

**Author:** ![mohammed\_cherif](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@mohammed\_cherif](https://discuss.elastic.co/u/mohammed_cherif)\
**Post date:** [October 26, 2017, 5:56pm UTC](https://discuss.elastic.co/t/aggregation-count-problem/104976/5 "2017-10-26T17:56:32Z")

</div>

For each product i want to get the max cutoff and do product.stillDate-Max (product.cutoff)

Thanks 🙂

---

<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:** [November 23, 2017, 5:56pm UTC](https://discuss.elastic.co/t/aggregation-count-problem/104976/6 "2017-11-23T17:56:37Z")

</div>

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