Date_histogram date formatter results in error in ElasticSearch Version 7.15 & above

The below query used to work fine in the Elasticsearch Versions 6.8.x to 7.13.4. But the same breaks from 7.15.x version. Kindly suggest the fix for this.

{
    "size": 0,
    "_source": false,
    "query": {
        "bool": {
            "must": [
                {
                    "exists": {
                        "field": "event_date"
                    }
                },
                {
                    "range": {
                        "event_date": {
                            "gte": "20210101",
                            "lte": "20211118",
                            "format": "yyyyMMdd"
                        }
                    }
                },
                {
                    "bool": {
                        "should": [
                            {
                                "exists": {
                                    "field": "access_count"
                                }
                            }
                        ]
                    }
                }
            ]
        }
    },
    "aggregations": {
        "date_interval": {
            "date_histogram": {
                "field": "event_date",
                "calendar_interval": "month",
                "min_doc_count": 1,
                "format": "yyyyMM",
                "keyed": true
            },
            "aggregations": {
                "ACTUAL_6087": {
                    "sum": {
                        "field": "access_count"
                    }
                }
            }
        },
        "ACTUAL_6087_SUMMARY": {
            "sum_bucket": {
                "buckets_path": "date_interval>ACTUAL_6087",
                "gap_policy": "skip",
                "format": "#,##0.00;(#,##0.00)"
            }
        },
        "groupby": {
            "composite": {
                "size": 1000,
                "sources": [
                    {
                        "d_5692_id": {
                            "date_histogram": {
                                "field": "event_date",
                                "calendar_interval": "month",
                                "format": "yyyyMM",
                                "order": "asc"
                            }
                        }
                    },
                    {
                        "d_5692_val": {
                            "date_histogram": {
                                "field": "event_date",
                                "calendar_interval": "month",
                                "format": "MMM YY",
                                "order": "asc"
                            }
                        }
                    }
                ]
            },
            "aggregations": {
                "ACTUAL_6087": {
                    "sum": {
                        "field": "access_count"
                    }
                }
            }
        },
        "d_ftype": {
            "terms": {
                "field": ""
            },
            "meta": {
                "fetch_type": "ACTUAL"
            }
        }
    }
}

O/P:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Format [DocValueFormat.DateTime(format[MMM YY] locale[], Z, MILLISECONDS)] created output it couldn't parse for value [1635724800000] of type [class java.lang.Long]. parsed value: [1609718400000(class java.lang.Long)]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Format [DocValueFormat.DateTime(format[MMM YY] locale[], Z, MILLISECONDS)] created output it couldn't parse for value [1635724800000] of type [class java.lang.Long]. parsed value: [1609718400000(class java.lang.Long)]",
        "suppressed": [
            {
                "type": "illegal_state_exception",
                "reason": "Failed to close the XContentBuilder",
                "caused_by": {
                    "type": "i_o_exception",
                    "reason": "Unclosed object or array found"
                }
            }
        ]
    },
    "status": 400
}

The version 7.13.4 yields the below result,

{
  "took": 6,
  "timed_out": false,
  "_shards": {
    "total": 22,
    "successful": 22,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 505,
      "relation": "eq"
    },
    "max_score": null,
    "hits": [
      
    ]
  },
  "aggregations": {
    "d_ftype": {
      "meta": {
        "fetch_type": "ACTUAL"
      },
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        
      ]
    },
    "groupby": {
      "after_key": {
        "d_5421_id": "202111",
        "d_5421_val": "Nov 21"
      },
      "buckets": [
        {
          "key": {
            "d_5421_id": "202110",
            "d_5421_val": "Oct 21"
          },
          "doc_count": 85,
          "ACTUAL_6087": {
            "value": 85.0
          }
        },
        {
          "key": {
            "d_5421_id": "202111",
            "d_5421_val": "Nov 21"
          },
          "doc_count": 420,
          "ACTUAL_6087": {
            "value": 420.0
          }
        }
      ]
    },
    "date_interval": {
      "buckets": {
        "202110": {
          "key_as_string": "202110",
          "key": 1633046400000,
          "doc_count": 85,
          "ACTUAL_6087": {
            "value": 85.0
          }
        },
        "202111": {
          "key_as_string": "202111",
          "key": 1635724800000,
          "doc_count": 420,
          "ACTUAL_6087": {
            "value": 420.0
          }
        }
      }
    },
    "ACTUAL_6087_SUMMARY": {
      "value": 505.0,
      "value_as_string": "505.00"
    }
  }
}

I'm looking for all the below different time grains,

"calendar_interval":"day","format":"dd MMM"
"calendar_interval":"week","format":"'Week' ww"
"calendar_interval":"month","format":"MMM YY"
"calendar_interval":"quarter","format":"'Q' q"
"calendar_interval":"year","format":"yyyy"

Appreciate any help w.r.t the above. Thanks in advance.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.