# TSVB Aggregation filter

**URL:** <https://discuss.elastic.co/t/tsvb-aggregation-filter/275477>\
**Category:** Kibana\
**Created:** [June 9, 2021, 5:09pm UTC](https://discuss.elastic.co/t/tsvb-aggregation-filter/275477 "2021-06-09T17:09:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam3546](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sam3546/32/79281_2.png) [@sam3546](https://discuss.elastic.co/u/sam3546)\
**Post date:** [June 9, 2021, 5:09pm UTC](https://discuss.elastic.co/t/tsvb-aggregation-filter/275477/1 "2021-06-09T17:09:50Z")

</div>

I want to show a gauge with a value that is calculated via an aggregation, the issue is i want the aggregations to be based on a filter, such that

I have a count value that is (number of docs with attribute: **A** )  
I have a count value that is (number of docs with attribute: **B** )

Currently you can only do a query that effects all calculations in the TSVB and theres not even an option to add a filter.

Is there a known work around for this?

I have read about script aggregations but not sure how to use that in TSVB.

I am using Elastic stack 7.9 and cannot upgrade due to dependencies.

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [June 9, 2021, 5:33pm UTC](https://discuss.elastic.co/t/tsvb-aggregation-filter/275477/2 "2021-06-09T17:33:54Z")

</div>

TSVB offers the _Filter Ratio_ function which lets you get the ratio of a function across two filters.

---

<div class="post-metadata">

**Author:** ![sam3546](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sam3546/32/79281_2.png) [@sam3546](https://discuss.elastic.co/u/sam3546)\
**Post date:** [June 10, 2021, 9:21am UTC](https://discuss.elastic.co/t/tsvb-aggregation-filter/275477/3 "2021-06-10T09:21:21Z")

</div>

Thanks @wylie that is useful to know, it does solve some of the problem. I phrased the original question wrong slightly, the filter im looking to use is a date range, the whole query is this,

% of tickets that have an invalid review field

a ticket is invalid if it,  
is older than 30 days and does not have a review field  
or  
has a review field where the date is not greater than todays date

So the filter i need is to check if it has the field and if the value of the field is greater than todays date.

Im not sure how to do that in Lucene?

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [June 10, 2021, 2:32pm UTC](https://discuss.elastic.co/t/tsvb-aggregation-filter/275477/4 "2021-06-10T14:32:18Z")

</div>

Most solutions I have for you involve upgrading.

TSVB filter ratio started using KQL instead of Lucene in 7.10, and this would let you use datemath like `date > now`. Another option is to add a runtime field in 7.12 (or scripted field in older versions) which will set a field on each document based on your criteria, but this only works with KQL- Lucene doesn't work with these script-based fields.

Your only option without upgrading is to use Vega. Vega has been fully supported since 7.10, but was much harder to use in 7.9 due to the lack of inspector and older versions. [We still have docs for 7.9 Vega](https://www.elastic.co/guide/en/kibana/7.9/vega-graph.html) which you can use, but upgrading will make it easier.

---

<div class="post-metadata">

**Author:** ![sam3546](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sam3546/32/79281_2.png) [@sam3546](https://discuss.elastic.co/u/sam3546)\
**Post date:** [June 11, 2021, 8:56am UTC](https://discuss.elastic.co/t/tsvb-aggregation-filter/275477/5 "2021-06-11T08:56:47Z")

</div>

Thanks again @wylie for the response, that is unfortunate but I appreciate the help, ill give vega a go.

Cheers

---

<div class="post-metadata">

**Author:** ![sam3546](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sam3546/32/79281_2.png) [@sam3546](https://discuss.elastic.co/u/sam3546)\
**Post date:** [June 29, 2021, 4:18pm UTC](https://discuss.elastic.co/t/tsvb-aggregation-filter/275477/6 "2021-06-29T16:18:58Z")

</div>

Follow up with solution,

Made do with a simplified pie chart

---

<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:** [July 27, 2021, 4:19pm UTC](https://discuss.elastic.co/t/tsvb-aggregation-filter/275477/7 "2021-07-27T16:19:39Z")

</div>

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