how to calculate percentage of a field log_count over all documents present in index.
Welcome to our community! ![]()
Do you mean a percentage of documents that have it over those that don't?
Let me explain this.
For example
we have one field called log_type. and in that field we have 12 different values like demo,demo2....demo12.
and suppose each log_type have 1000 documents.
Now, I want to calculate document count percentage for log_type=demo1.
so the value will be like demo have 1000 documents and all log_types including demo1 have 12000 .
so the calculation will be like (demo1/all_log_types)*100= 8.3333
You can use Terms aggregation | Elasticsearch Guide [8.8] | Elastic to create the first lot of buckets.
From there you have two options;
- calcuate the percentage outside Elasticsearch
- use something like this Using doc_count to calculate percentage after aggregation - #2 by spinscale
Elasticsearch doesn't provide this sort of output itself.
I think the issue with those is Kibana calculates the percentages post Elasticsearch query, whereas they want the response from Elasticsearch to show the breakdown.

