The Avg value in elasticsearch is incorrect

I have an issue about the avg mathematical operation in elasticsearch.

In the singlestat panel , I want to get average download count per day so the interval is set to 1d and options-value-stat is set to “avg”.
When I set timerange to “yesterday”,it shows 1.24Mil, but in fact the total download is 2.49Mil, so the avg shoud be 2.49Mil but only half.

Next,when I set timerange to “last 7 days”,we can get total count from graph panel is 28.16Mil, 28.16/7=4.02Mil/day , but it shows 3.52Mil/day as 28.16/8. the graph panel(interval is also set to 1d) and singlestat panel avg value both incorrect.
why does the days plus 1 when I calculate the average?this is my question
I’m not sure if I have a clear statement :joy: wish for your reply

miss a screenshot

check what Elasticsearch returns, maybe it is not returning what you think, it probably returns 2 values, one very low and one for the whole day, which explains the low avg.

Upgrade to v5 and you can use the query inspector to investigate what the query is sending to ES and what it is returning, Using Grafana's Query Inspector to troubleshoot issues

thanks a lot
I upgrade to latest version and check the request&response

I split index by day in my elasticsearch.
I set time range to “yesterday”, the query index should be “20180528” and buckets should be 1,but acturally it’s not like this. And then I change timezone to UTC,it works. but I should use local time to show

In ES, the mapping is "esTimeField": { "type": "date", "format": "strict_date_optional_time||epoch_millis" }
and the value is like this:“esTimeField”: “2018-05-22T16:17:27.564+08:00”

I’m new in elasticsearch and grafana both:sweat_smile:
So,what should I do to achieve the desired effect.
Wish for your reply.
Best regards!

thanks for taking the time,I checked request&response and post screenshots above.