# How to set min\_doc\_count for bucket in Lens visualization?

**URL:** <https://discuss.elastic.co/t/how-to-set-min-doc-count-for-bucket-in-lens-visualization/298519>\
**Category:** Kibana\
**Tags:** lens\
**Created:** [March 1, 2022, 2:00pm UTC](https://discuss.elastic.co/t/how-to-set-min-doc-count-for-bucket-in-lens-visualization/298519 "2022-03-01T14:00:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakn](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@jakn](https://discuss.elastic.co/u/jakn)\
**Post date:** [March 1, 2022, 2:00pm UTC](https://discuss.elastic.co/t/how-to-set-min-doc-count-for-bucket-in-lens-visualization/298519/1 "2022-03-01T14:00:08Z")

</div>

I need to create a Formula Metric in a Lens visualization on some terms/top value buckets.

I only want to calculate the metric for buckets with at least 10 records. How do I ensure that?

I know that in the aggregation-based visualizations I can add the following JSON input in the Advanced settings for the bucket specification: `{"min_doc_count": 10}`.

![image](https://us1.discourse-cdn.com/elastic/original/3X/1/f/1f8d9283921ae0131da09e58437b7961e89c3a83.png)

How can I do something similar in a Lens visualization, which I need to be able to calculate my formula metric?

---

<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:** [March 9, 2022, 4:19pm UTC](https://discuss.elastic.co/t/how-to-set-min-doc-count-for-bucket-in-lens-visualization/298519/2 "2022-03-09T16:19:48Z")

</div>

I don't think in Lens you can filter by the result of your aggregation at this moment.

Any ideas @flash1293 ?

---

<div class="post-metadata">

**Author:** ![drewdaemon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drewdaemon/32/97779_2.png) [@drewdaemon](https://discuss.elastic.co/u/drewdaemon)\
**Post date:** [March 16, 2022, 3:05pm UTC](https://discuss.elastic.co/t/how-to-set-min-doc-count-for-bucket-in-lens-visualization/298519/3 "2022-03-16T15:05:26Z")

</div>

Hi @jakn—This is not currently possible in Lens. You could either stick with the agg-based visualizations for now, or you could create a [custom visualization](https://www.elastic.co/guide/en/kibana/current/vega.html) (Vega) which gives you complete control over the query that is used to back the 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:** [April 13, 2022, 3:06pm UTC](https://discuss.elastic.co/t/how-to-set-min-doc-count-for-bucket-in-lens-visualization/298519/4 "2022-04-13T15:06:15Z")

</div>

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