ElasticSearch日期_直方图未显示全范围聚合

uqcuzwp8  于 2022-12-26  发布在  ElasticSearch
关注(0)|答案(1)|浏览(138)

这是我的查询。我使用的date_histogram的范围从2021年6月到12月。

{
  "from": 0,
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "medicalRecordDiagnosesDischarge.catDiseaseGroupDetail.catDiseasesGroup.diseasesGroupId": {
              "value": 13,
              "boost": 1
            }
          }
        },
        {
          "range": {
            "examinationDate": {
              "from": "2021-01-01T00:00:00.000Z",
              "to": "2022-01-01T00:00:00.000Z",
              "include_lower": true,
              "include_upper": false,
              "boost": 1
            }
          }
        }
      ]
    }
  },
  "aggregations": {
    "agg_name": {
      "date_histogram": {
        "field": "examinationDate",
        "format": "MM",
        "calendar_interval": "1M",
        "offset": 0,
        "order": {
          "_key": "asc"
        },
        "keyed": false,
        "min_doc_count": 0
      }
    }
  }
}

结果:

"buckets" : [
        {
          "key_as_string" : "01",
          "key" : 1609459200000,
          "doc_count" : 66
        },
        {
          "key_as_string" : "02",
          "key" : 1612137600000,
          "doc_count" : 18
        },
        {
          "key_as_string" : "03",
          "key" : 1614556800000,
          "doc_count" : 114
        },
        {
          "key_as_string" : "04",
          "key" : 1617235200000,
          "doc_count" : 15
        },
        {
          "key_as_string" : "05",
          "key" : 1619827200000,
          "doc_count" : 22
        },
        {
          "key_as_string" : "06",
          "key" : 1622505600000,
          "doc_count" : 1
        },
        {
          "key_as_string" : "07",
          "key" : 1625097600000,
          "doc_count" : 2
        },
        {
          "key_as_string" : "08",
          "key" : 1627776000000,
          "doc_count" : 3
        }
      ]

如您所见,结果仅显示01 -〉08个月的数据。缺少09、10、11、12个月的数据
我想要的查询结果是:

{
          "key_as_string" : "01"
        },
        {
          "key_as_string" : "02"
        },
        {
          "key_as_string" : "03"
        },
        {
          "key_as_string" : "04"
        },
        {
          "key_as_string" : "05"
        },
        {
          "key_as_string" : "06"
        },
        {
          "key_as_string" : "07"
        },
        {
          "key_as_string" : "08"
        },
        {
          "key_as_string" : "09"
        },
        {
          "key_as_string" : "10"
        },
        {
          "key_as_string" : "11"
        },
        {
          "key_as_string" : "12"
        }

我怎样才能得到上面的结果?我尝试extended_bounds,但它是错误的双倍结果。(与calendar_interval相同,是季度)

zwghvu4y

zwghvu4y1#

您是否尝试过在聚合中使用size参数?

{
   "aggregations": {
    "agg_name": {
      "date_histogram": {
        "field": "examinationDate",
        ...
        "size": 12
      }
    }
  }
}

相关问题