如何调整日期字段上的日期范围聚合值?

How to adjust date range aggregation values on date field?

我正在尝试使用每个文档中的日期字段对文档进行分组。我需要根据过去 30 天、30-60 天、60-90 天的文档对它们进行搜索。通过应用以下范围聚合。我的日期范围完全错误。

{
  "aggs": {
    "dateRanges": {
      "date_range": {
        "field": "date",
        "keyed": true,
        "format": "yyyy-mm-dd", 
        "ranges": [
            {"from": "now/d",
              "to": "now/d-1M",
              "key": "Last 30 Days"
            },
            {"from": "now/d-1M",
              "to": "now/d-2M",
              "key": "Last 60 Days"
            },
            {"from": "now/d-2M",
              "to": "now/d-3M",
              "key": "Last 90 Days"
            }
          ]

      }
    }
  }
}

当前结果:

  "aggregations" : {
    "dateRanges" : {
      "buckets" : {
        "Last 90 Days" : {
          "from" : 1.585008E12,
          "from_as_string" : "2020-00-24",
          "to" : 1.5825024E12,
          "to_as_string" : "2020-00-24",
          "doc_count" : 0
        },
        "Last 60 Days" : {
          "from" : 1.5876864E12,
          "from_as_string" : "2020-00-24",
          "to" : 1.585008E12,
          "to_as_string" : "2020-00-24",
          "doc_count" : 0
        },
        "Last 30 Days" : {
          "from" : 1.5902784E12,
          "from_as_string" : "2020-00-24",
          "to" : 1.5876864E12,
          "to_as_string" : "2020-00-24",
          "doc_count" : 0
        }
      }
    }
  }
}

为什么每个桶都有相同的 'from' 和 'to' 值?

除了你的日期格式不对,其他都正确,你需要做如下修改

    "format": "yyyy-MM-dd", 
                    ^^
                    ||
          month instead of minutes