I am trying to do histogram in sql query for month and it does not work
daily or hourly works fine here is query
GET _sql?format=txt
{
"query": """
select histogram(achieved, INTERVAL 1 month) as m, count(*) as c from "resource-*" where
achieved between '2019-01-01' and '2019-12-31'
group by m
"""
}
Output comes out with middle of the month. and first one is even for 2018. Where am I wrong?
Thank you @elasticforme.
The relevant part in the query you provided is "fixed_interval" : "2592000000ms" which represent the length of a month (30 days) in milliseconds.
In SQL we chose to represent these as fixed intervals, and the behavior you get is the result of this choice. We did make a change for YEAR to behave like a calendar interval and we could to the same for MONTH and maybe DAY.
Can you, please, open an issue in https://github.com/elastic/elasticsearch/ about an improvement to GROUP BY HISTOGRAM where the interval is 1 MONTH or 1 DAY? Thanks.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.