# Use threshold on minimum number of observations for showing data on chloropleth map

**URL:** <https://discuss.elastic.co/t/use-threshold-on-minimum-number-of-observations-for-showing-data-on-chloropleth-map/307980>\
**Category:** Kibana\
**Tags:** maps\
**Created:** [June 23, 2022, 9:56am UTC](https://discuss.elastic.co/t/use-threshold-on-minimum-number-of-observations-for-showing-data-on-chloropleth-map/307980 "2022-06-23T09:56:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NiklasHBB](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@NiklasHBB](https://discuss.elastic.co/u/NiklasHBB)\
**Post date:** [June 23, 2022, 9:56am UTC](https://discuss.elastic.co/t/use-threshold-on-minimum-number-of-observations-for-showing-data-on-chloropleth-map/307980/1 "2022-06-23T09:56:18Z")

</div>

I have followed the [reverse geocoding example](https://www.elastic.co/guide/en/kibana/current/reverse-geocoding-tutorial.html) and the basics work great using Kibana 7.16. I have left the 'apply global search to layer data' option turned off so that the map updates when I filter observations in a dashboard.

Now I would like to limit the polygons shown on the map to those which meet a minimum number of observations (e.g. show only polygons with at least 5 IP addresses). Is there a way to make this work? If so, can I adjust the behaviour of the threshold to also filter the remaining dashboard or, alternatively, _not_ to filter the remaining dashboard?

![grafik](https://us1.discourse-cdn.com/elastic/original/3X/d/2/d20f7faf87c2f68494a455655fa04c1ab42c31eb.png)

---

<div class="post-metadata">

**Author:** ![jsanz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsanz/32/53734_2.png) [@jsanz](https://discuss.elastic.co/u/jsanz)\
**Post date:** [June 23, 2022, 11:35am UTC](https://discuss.elastic.co/t/use-threshold-on-minimum-number-of-observations-for-showing-data-on-chloropleth-map/307980/2 "2022-06-23T11:35:58Z")

</div>

Unfortunately there is not support for aggregation results filtering in Elastic Maps ☹

Related issues:

> <https://github.com/elastic/kibana/issues/55520>
>
> \*\*Describe the feature:\*\*
> 
> Enable a way for filtering buckets visualized in a …map's
> grid visualization.
> 
> This can potentially be implemented by 
> adding an additional \[bucket-selector pipeline aggregation\](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html) to the ES query.
> 
> \*\*Describe a specific use case for the feature:\*\*
> 
> Sometimes it may be necessary to hide buckets in a map's 
> grid aggregation from showing buckets with a certain count.
> 
> https://github.com/elastic/elasticsearch/pull/50480 describes a scenario where
> it would be nice to have \`min\_doc\_count\` as 
> an additional parameter to a visualization so one can filter out 
> buckets that have a lower count than this.

> <https://github.com/elastic/kibana/issues/63401>
>
> I have tabular data by districts and days. Each row contains diff between the cu…rrent and previous days, i.e. relative value. 
> 
> district | day | metric 
> ----------+------------+--------
> D1 | 2020-04-12 | -11     
> D1 | 2020-04-13 | 40
> D2 | 2020-04-13 | 20     
> D1 | 2020-04-14 | 11         
> D1 | 2020-04-15 | -50
> 
> I need to visualize this data on Kibana's region map. 
> 
> So, the \*metric\* is grouped by \*district\* and summarized. Here is the ElasticSearch query generated by Kibana:
> 
> {"aggs": {
> "2": {
> "terms": {
> "field": "district",
> "size": 300,
> "order": {
> "1": "desc"
> }},
> "aggs": {
> "1": {
> "sum": {
> "field": "metric"
> }}}}},
> "query": {
> "bool": {
> "must": \[{
> "range": {
> "@timestamp": {
> "format": "strict\_date\_optional\_time",
> "gte": "2020-04-12T00:00:00.0Z",
> "lte": "2020-04-16T00:00:00.0Z"
> }}}\]}}}  
> 
> Depending on the selected data rage the result will vary. For example, this query selects all data (see @timestamp filter) and metric values for districts \*\*D1\*\* and \*\*D2\*\* will be \*\*-10\*\* and \*\*20\*\*. If I'll change the filter to select data for 12-13 April it will be \*-11 + 40\* = \*\*29\*\* for \*\*D1\*\* and \*\*20\*\* for \*\*D2\*\*. 
> 
> In Kibana I need to filter out buckets with negative \*\*sum(metric)\*\* value and show districts only with a positive sum value. I couldn't find any working solution. I've tried
> 
> - Kibana's \*\*JSON input\*\* + \[Bucket Selector
> Aggregation\](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html)
> Visual 
> - Kibana's Vega Graphs, but it seems that it doesn't support region maps.
> I'd like to avoid it as it's quite complicated.
> - Build a new index based on the existing ones, but it's not possible as
> a result depends on a date range filter, so I cannot pre-calculate metrics and filter out negatives because I don't know what date range is in advanced
> 
> Nothing of this worked for me. I was able to compose a working Elastic Search query that does exactly what I want, but I don't know how to visualize it using the region map:
> 
> {"aggs": {
> "2": {
> "terms": {
> "field": "district",
> "size": 300,
> "order": {
> "1": "desc"
> }},
> "aggs": {
> "1": {
> "sum": {
> "field": "metric"
> },
> "1\_bucket\_selector": { -- here is main part, how get it in region map?
> "bucket\_selector": {
> "buckets\_path": {
> "metricSum": "1"
> },
> "script": "params.metricSum \> 0"
> }}}}}}}
> 
> 
> So, any workaround to achieve what I want?
> 
> \[Here\](https://discuss.elastic.co/t/introduce-bucket-selector-or-any-post-aggregation-filtering-like-having-in-sql-into-region-map-elastic-search-kibana/227687) is a related topic on Kibana forum
> 
> ELK stack version is 7.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:** [July 21, 2022, 11:36am UTC](https://discuss.elastic.co/t/use-threshold-on-minimum-number-of-observations-for-showing-data-on-chloropleth-map/307980/3 "2022-07-21T11:36:26Z")

</div>

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