以下是一个不考虑年份的Elasticsearch日期直方图聚合的解决方法的代码示例:
POST /your-index/_search
{
"size": 0,
"aggs": {
"date_histogram": {
"field": "your-date-field",
"calendar_interval": "month",
"format": "MM-dd"
}
}
}
在上面的示例中,您需要将your-index
替换为您要执行聚合的索引名称,your-date-field
替换为包含日期值的字段名称。
聚合使用date_histogram
聚合类型,它将日期字段划分为指定的时间间隔(在示例中为月份)。您可以根据需要更改时间间隔。format
参数用于指定输出的日期格式。
通过运行上面的查询,您将获得一个直方图聚合结果,其中包含每个月的文档计数。