From b5c8cbea10beb71762efb7af4c67a15876e9ec3e Mon Sep 17 00:00:00 2001 From: Matt Bargar Date: Fri, 7 Sep 2018 12:16:33 -0400 Subject: [PATCH] Force date format in context query (#22684) * Force date format in context query Fixes issue reported in https://discuss.elastic.co/t/view-surrounding-documents-causes-failed-to-parse-date-field-exception/147234 The default date field format is `strict_date_optional_time||epoch_millis` so we didn't run into this during testing. If the user has custom mappings for their timestamp field and `epoch_millis` isn't one of the optional formats the context query will fail since it always sends the date in millis. This change forces the query to accept the date in millis. * Update tests --- .../kibana/public/context/api/__tests__/predecessors.js | 2 +- .../kibana/public/context/api/__tests__/successors.js | 2 +- src/core_plugins/kibana/public/context/api/context.js | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core_plugins/kibana/public/context/api/__tests__/predecessors.js b/src/core_plugins/kibana/public/context/api/__tests__/predecessors.js index 2e461ff836fe6d..7caeec57f4cf2d 100644 --- a/src/core_plugins/kibana/public/context/api/__tests__/predecessors.js +++ b/src/core_plugins/kibana/public/context/api/__tests__/predecessors.js @@ -103,7 +103,7 @@ describe('context app', function () { // should have started at the given time expect(intervals[0].gte).to.eql(MS_PER_DAY * 3000); // should have ended with a half-open interval - expect(_.last(intervals)).to.only.have.key('gte'); + expect(_.last(intervals)).to.only.have.keys('gte', 'format'); expect(intervals.length).to.be.greaterThan(1); expect(hits).to.eql(searchSourceStub._stubHits.slice(0, 3)); diff --git a/src/core_plugins/kibana/public/context/api/__tests__/successors.js b/src/core_plugins/kibana/public/context/api/__tests__/successors.js index 1974d55655e25f..e9c3e94829b71f 100644 --- a/src/core_plugins/kibana/public/context/api/__tests__/successors.js +++ b/src/core_plugins/kibana/public/context/api/__tests__/successors.js @@ -103,7 +103,7 @@ describe('context app', function () { // should have started at the given time expect(intervals[0].lte).to.eql(MS_PER_DAY * 3000); // should have ended with a half-open interval - expect(_.last(intervals)).to.only.have.key('lte'); + expect(_.last(intervals)).to.only.have.keys('lte', 'format'); expect(intervals.length).to.be.greaterThan(1); expect(hits).to.eql(searchSourceStub._stubHits.slice(-3)); diff --git a/src/core_plugins/kibana/public/context/api/context.js b/src/core_plugins/kibana/public/context/api/context.js index 68ca81e83a20eb..6b60eea7b76759 100644 --- a/src/core_plugins/kibana/public/context/api/context.js +++ b/src/core_plugins/kibana/public/context/api/context.js @@ -216,6 +216,7 @@ function fetchContextProvider(indexPatterns, Private) { filter: { range: { [timeField]: { + format: 'epoch_millis', ...startRange, ...endRange, }