Hi,
I'm in situation to calculate MoM, YoY, WoW for a metric. I'm thinking of fetching all the docs and filtering in programming language. But I feel its not a right way. Can some one help me in forming Query DSL so that load will be on ES server.
Hi,
I'm in situation to calculate MoM, YoY, WoW for a metric. I'm thinking of fetching all the docs and filtering in programming language. But I feel its not a right way. Can some one help me in forming Query DSL so that load will be on ES server.
I suspect you are looking for the date_histogram aggregation? https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
Your aggregation would look something like that for YoY:
POST /sales/_search?size=0
{
"aggs" : {
"YoY" : {
"date_histogram" : {
"field" : "my_date_field",
"interval" : "1Y"
},
"aggs": {
"metric_YoY": {
"avg": {
"field": "my_metric_field"
}
}
}
}
}
}
I used an average aggregation so that you can follow how the average value of the my_metric_field moves over time, but you can use any aggregation, eg. sum, percentiles, etc.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
© 2020. All Rights Reserved - Elasticsearch
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.