How to aggregate based on the number of items in a field?

On Elasticsearch I have a field named Itinerary that can contain multiple values (from 1 up to 6), for example in the picture below there's 2 items in the field.


Is there a way I can aggregate based on the number of items in the field? Having something like:

1 item : 2
2 item : 4
...

I would go with an ingest processor that calculates the size of the number of fields before indexing. This way, querying stays fast.

If you just want to test this feature, try a runtime field doing that calculation, so that you can filter on it - and even replace it with an indexed field later without replacing your query.

Hope this helps!