Skip to content

Multiple date formats in date_histogram aggregation #39916

@Mpdreamz

Description

@Mpdreamz

The following worked in 6.x

"date_histogram": {
    "extended_bounds": {
        "max": "2016-06-06T12:01:02.123",
        "min": "2014-06-06T12:01:02.123"
    },
    "field": "startedOn",
    "format": "yyyy-MM-dd'T'HH:mm:ss||date_optional_time",
    "interval": "month",
    "min_doc_count": 2,
    "missing": "2015-06-06T12:01:02.123",
    "order": {
         "_count": "asc"
    }
}

In 7.0.0-beta1 it fails with the following:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "parse_exception",
        "reason" : "failed to parse date field [2014-06-06T12:01:02.123] with format [yyyy-MM-dd'T'HH:mm:ss||date_optional_time]: [Text '2014-06-06T12:01:02.123' could not be parsed, unparsed text found at index 19]",
        "stack_trace" : "ElasticsearchParseException[failed to parse date field [2014-06-06T12:01:02.123] with format [yyyy-MM-dd'T'HH:mm:ss||date_optional_time]: [Text '2014-06-06T12:01:02.123' could not be parsed, unparsed text found at index 19]]; nested: DateTimeParseException[Text '2014-06-06T12:01:02.123' could not be parsed, unparsed text found at index 19];\r\n\tat org.elasticsearch.common.time.JavaDateMathParser.parseDateTime(JavaDateMathParser.java:233)\r\n\tat org.elasticsearch.common.time.JavaDateMathParser.parse(JavaDateMathParser.java:75)\r\n\tat org.elasticsearch.search.DocValueFormat$DateTime.parseLong(DocValueFormat.java:229)\r\n\tat org.elasticsearch.search.aggregations.bucket.histogram.ExtendedBounds.parseAndValidate(ExtendedBounds.java:156)\r\n\tat org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder.innerBuild(DateHistogramAggregationBuilder.java:455)\r\n\tat org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder.doBuild(ValuesSourceAggregationBuilder.java:315)\r\n\tat org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder.doBuild(ValuesSourceAggregationBuilder.java:39)\r\n\tat org.elasticsearch.search.aggregations.AbstractAggregationBuilder.build(AbstractAggregationBuilder.java:139)\r\n\tat org.elasticsearch.search.aggregations.AggregatorFactories$Builder.build(AggregatorFactories.java:333)\r\n\tat org.elasticsearch.search.SearchService.parseSource(SearchService.java:800)\r\n\tat org.elasticsearch.search.SearchService.createContext(SearchService.java:607)\r\n\tat org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:582)\r\n\tat org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:385)\r\n\tat org.elasticsearch.search.SearchService.access$100(SearchService.java:123)\r\n\tat org.elasticsearch.search.SearchService$2.onResponse(SearchService.java:357)\r\n\tat org.elasticsearch.search.SearchService$2.onResponse(SearchService.java:353)\r\n\tat org.elasticsearch.search.SearchService$4.doRun(SearchService.java:1068)\r\n\tat org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)\r\n\tat org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:41)\r\n\tat org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:751)\r\n\tat org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)\r\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\r\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\r\n\tat java.base/java.lang.Thread.run(Thread.java:834)\r\nCaused by: java.time.format.DateTimeParseException: Text '2014-06-06T12:01:02.123' could not be parsed, unparsed text found at index 19\r\n\tat java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2049)\r\n\tat java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1874)\r\n\tat org.elasticsearch.common.time.JavaDateMathParser.parseDateTime(JavaDateMathParser.java:223)\r\n\t... 23 more\r\n"
      }
    ],

Specifying only

    "format": "date_optional_time",

Results in no error however.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions