日期范围查询中的弹性搜索间隔

时间:2019-02-19 13:54:42

标签: elasticsearch

我有一个查询要求如下:

{
  "size": 0,
  "_source": [
    "dateCreated"
  ],
  "query": {
    "bool": {
      "must": {
        "range": {
          "date_published": {
            "from": "2019-01-01", //Fixed date
            "to": "--15 days from given 'from' date--" //Cannot find solution for this
          }
        }
      }
    }
  }
}

我找不到像这样的简单要求的文档。

1 个答案:

答案 0 :(得分:2)

使用date math,您可以实现期望的目标

{
  "size": 0,
  "_source": [
    "dateCreated"
  ],
  "query": {
    "bool": {
      "must": {
        "range": {
          "date_published": {
            "from": "2019-01-01",
            "to": "2019-01-01||+15d"
          }
        }
      }
    }
  }
}