Skip to content

Commit

Permalink
Force date format in context query (#22684)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Bargs committed Sep 7, 2018
1 parent 20963e3 commit b5c8cbe
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/core_plugins/kibana/public/context/api/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ function fetchContextProvider(indexPatterns, Private) {
filter: {
range: {
[timeField]: {
format: 'epoch_millis',
...startRange,
...endRange,
}
Expand Down

0 comments on commit b5c8cbe

Please sign in to comment.