# Value\_count aggregation based on key name pattern

**URL:** <https://discuss.elastic.co/t/value-count-aggregation-based-on-key-name-pattern/278402>\
**Category:** Elasticsearch\
**Created:** [July 12, 2021, 9:21am UTC](https://discuss.elastic.co/t/value-count-aggregation-based-on-key-name-pattern/278402 "2021-07-12T09:21:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ray\_Garcia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ray_garcia/32/91498_2.png) [@Ray\_Garcia](https://discuss.elastic.co/u/Ray_Garcia)\
**Post date:** [July 12, 2021, 9:21am UTC](https://discuss.elastic.co/t/value-count-aggregation-based-on-key-name-pattern/278402/1 "2021-07-12T09:21:44Z")

</div>

Hi all, Elastic newbie here. I just started playing with ES a week ago. It seems super powerful and it fits perfectly with some aggregated data queries I'm performing.  
Some of them are already done (and they work flawlesly!) but some other are being so difficult to achieve.

For example:  
I have a dataset having this structure:  
someKindOfData | topic\_a | topic\_b | topic\_c | someMoreKindOfData

I'm trying to get a value\_count aggregation of every field which its key match a pattern like 'topic\_\*'.

 ![imagen](https://us1.discourse-cdn.com/elastic/original/3X/1/3/13d553650735c8c5dd77ed23e718f9b439134282.png)  
The number on this picture is a value, but I want to get the number of times every topic appears (because not all the documents has the same kind of topics\_, they are like hundreds, and every document only show a few, the ones selected by the document user)  
So, if I'm looking for a query that has a kind of value\_count aggregation like:

```auto
aggregations: {
  topic_a: {
    value: 84
  },
  topic_b: {
    value: 91
  },
  ...
}

```

Could it be done in ES? Any clue about how to achieve this?

Thank you all!

---

<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:** [August 9, 2021, 9:22am UTC](https://discuss.elastic.co/t/value-count-aggregation-based-on-key-name-pattern/278402/2 "2021-08-09T09:22:33Z")

</div>

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