Value_count aggregation based on key name pattern

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_*'.


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:

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!

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