Return only Keys matching a pattern in Aggregations

Hello,

is there a way to only return keys in aggregations that match a certain pattern?

I have an aggregation on sports that returns

Football => 100,
Handball => 50,
Hockey => 40,
Racquetball => 30,
Tennis => 20

Now I just want to return keys that contain "ball" , so in this example Tennis and Hockey would not make it into the aggregation.

I saw the bucket_selector which I think would solve this but it can only work with numbers?

Thank you so much

Why not just query on the field sports? with wildcard or regex query?
Then your aggregation will be applied only on the results of the query.

Sorry, while this works fine for strings, the field is an array with interests, eg

['Football','Hockey','Racquetball']

so the query filter works fine of course to only get items that have at least one 'ball' as an interest but in this case the terms aggregation would also return 'Hockey' ?

Oh ok I get your point.
Indeed, I think with the bucket selector this is doable, with a script that will evaluate your regex and returns a boolean.

the problem I ran into with the bucket_selector was that I got an error that the bucket_path has a string value and is not numeric?

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