# Kibana Visualization: count the number of occurrences of a term, within a certain field of the latest document

**URL:** <https://discuss.elastic.co/t/kibana-visualization-count-the-number-of-occurrences-of-a-term-within-a-certain-field-of-the-latest-document/216776>\
**Category:** Kibana\
**Created:** [January 28, 2020, 8:12am UTC](https://discuss.elastic.co/t/kibana-visualization-count-the-number-of-occurrences-of-a-term-within-a-certain-field-of-the-latest-document/216776 "2020-01-28T08:12:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spiro](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@spiro](https://discuss.elastic.co/u/spiro)\
**Post date:** [January 28, 2020, 8:12am UTC](https://discuss.elastic.co/t/kibana-visualization-count-the-number-of-occurrences-of-a-term-within-a-certain-field-of-the-latest-document/216776/1 "2020-01-28T08:12:35Z")

</div>

I have to create a visualization which captures the number of devices having unknown agent versions, e.g. capture 3 groups: version 5.6.1 having 1 device, 5.7.2 having 2 devices, and 5.8.1 having 5 devices. There will be new versions in the future and I need a way to ensure that these new groups (unknown versions) will be shown, without having to be explicitly mapped out and maintained in Elasticsearch or Logstash.

Currently I have a field, Agent\_Version, where I send each version group, a number of times. The number of times depends on how many devices have that version, e.g. Agent\_Version =\> 5.6.1, 5.7.2, 5.7.2, 5.8.1, 5.8.1, 5.8.1, 5.8.1, 5.8.1.

Is there a way to count the occurrence of each term in this field, within the latest document only?

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [January 28, 2020, 1:01pm UTC](https://discuss.elastic.co/t/kibana-visualization-count-the-number-of-occurrences-of-a-term-within-a-certain-field-of-the-latest-document/216776/2 "2020-01-28T13:01:17Z")

</div>

How does a document looks like? The main way to do math/operations/anything in the scope of a single document is the scripted field functionality.

---

<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:** [February 25, 2020, 1:01pm UTC](https://discuss.elastic.co/t/kibana-visualization-count-the-number-of-occurrences-of-a-term-within-a-certain-field-of-the-latest-document/216776/3 "2020-02-25T13:01:32Z")

</div>

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