I'm working with Kibana Lens and I don't understand the results I'm getting. I started by running these commands in Dev Tools on a completely empty index called avg1
POST avg1/_doc
{
"order_items": [
{"product": {"name":"laptop","price": 1000}},
{"product": {"name":"keyboard","price": 10}}
]
}
POST avg1/_doc
{
"order_items": [
{"product": {"name":"laptop","price": 1000}}
]
}
Then I made a Kibana Data View called avg1
.
Then I went to Kibana Lens to create a bar graph.
I chose Top 5 Values on order_items.product.name.keyword
for the X axis.
I chose Average on order_items.product.price
for the Y axis.
I was expecting these results:
laptop: 1000 ----> because (1000 laptop + 1000 laptop) / 2 laptops = 1000
keyboard: 10 ----> because 10 keyboard / 1 keyboard = 10
Instead, I got these results:
laptop: 670
keyboard: 505
How was the 670 and 505 calculated?
OK! I see that 505 = (1000 + 10) / 2
. And I see that 670 = (1000 + 1000 + 10) /3
.
What I don't understand is why these formulas were used instead of the classical definition of "average"? For example, why isn't the formula for average simply "sum of all items that are laptop divided by the number of instances of laptop". And "sum of all items that are keyboard divided by the number of instances of keyboard"?