I would like to count the same log messages in Kibana. With the Size set to 200, it turns out that there are two results that happened twice

But, if I lower the Size to 5, I don't see those two:

It should show me top 5 rows, ordered by count. I expected something like this:
| LogMessage | Count |
|------------|-------|
| xx | 2 |
| yy | 2 |
| zz | 1 |
| qq | 1 |
| ww | 1 |
What am I missing?
The issue is the little warning about
Analyzed Field. You should use a keyword field.With analyzed fields, the analyzer breaks down the original string during indexing into sub-strings to facilitate search use cases (handling things like word boundaries, punctuation, case insensitivity, declination, etc)
A
keywordfield is just a simple string.What's probably happening is that you have data like
With an analyzed field, if you have a
termsagg of size 2 you might (depending on the sort order) getaandbWith a larger terms agg, the top sub-string will be
xThis is a simplified example, but I hope it gets the issue across.
The Terms Aggregation docs have a good section about how to avoid/solve this issue.