date.getHourOfDay()在聚合中给出奇怪的结果

时间:2018-08-24 19:12:43

标签: elasticsearch elasticsearch-5 elasticsearch-aggregation

我正在索引一些事件并试图获得唯一的小时数,但是术语汇总给出了奇怪的响应。我有以下查询。

{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "City": [
              "Chicago"
            ]
          }
        },
        {
          "range": {
            "eventDate": {
              "gte": "2018-06-22",
              "lte": "2018-06-22"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "Hours": {
      "terms": {
        "script": "doc['eventDate'].date.getHourOfDay()"
      }
    }
  }
}

此查询产生以下响应。

"buckets": [
        {
          "key": "19",
          "doc_count": 12
        },
        {
          "key": "9",
          "doc_count": 7
        },
        {
          "key": "15",
          "doc_count": 4
        },
        {
          "key": "16",
          "doc_count": 4
        },
        {
          "key": "20",
          "doc_count": 4
        },
        {
          "key": "12",
          "doc_count": 2
        },
        {
          "key": "6",
          "doc_count": 2
        },
        {
          "key": "8",
          "doc_count": 2
        },
        {
          "key": "10",
          "doc_count": 1
        },
        {
          "key": "11",
          "doc_count": 1
        }
      ]

现在,我更改了获取过去一个月活动的范围

  

{                     “范围”: {                       “活动日期”: {                         “ gte”:“ 2018-05-22”,                         “ lte”:“ 2018-06-22”                       }                     }                   }

我得到的答复是

"Hours": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 1319,
      "buckets": [
        {
          "key": "22",
          "doc_count": 805
        },
        {
          "key": "14",
          "doc_count": 370
        },
        {
          "key": "15",
          "doc_count": 250
        },
        {
          "key": "21",
          "doc_count": 248
        },
        {
          "key": "16",
          "doc_count": 195
        },
        {
          "key": "0",
          "doc_count": 191
        },
        {
          "key": "13",
          "doc_count": 176
        },
        {
          "key": "3",
          "doc_count": 168
        },
        {
          "key": "20",
          "doc_count": 159
        },
        {
          "key": "11",
          "doc_count": 148
        }
      ]
    }

如您所见,我在第一个查询的响应中得到了带有键6、8、9、10和12 的存储桶,但是在第二个查询中却没有,这与第一次查询返回的文档非常奇怪是第二个查询的一小部分。这是一个错误还是我遗漏了一些明显的东西?

谢谢

0 个答案:

没有答案