Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] Fix field stats for epoch time format (#148288)
Closes #148140 ## Summary This PR fixes time format so it can work also for epoch. Before: <img width="400" alt="Screenshot 2023-01-03 at 12 33 17" src="https://user-images.githubusercontent.com/1415710/210350243-b3ae1d1a-4c76-46e7-930f-0ca9835dc121.png"> After: <img width="400" alt="Screenshot 2023-01-03 at 12 32 49" src="https://user-images.githubusercontent.com/1415710/210350274-af80f558-6a32-4da6-9cb9-857a8cb3de70.png"> Sample data for testing: ``` PUT test PUT test/_mapping { "properties": { "timestamp": { "type": "date", "format": "epoch_second" }, "message": { "type": "keyword" }, "bytes": { "type": "long" } } } POST test/_doc/1 { "timestamp": 1669912088.9230318, "message": "Message 1", "bytes": 250 } POST test/_doc/2 { "timestamp": 1669912088.9230319, "message": "Message 2", "bytes": 20 } ```
- Loading branch information
Showing
3 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
184 changes: 184 additions & 0 deletions
184
src/plugins/unified_field_list/common/utils/__snapshots__/field_stats_utils.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
153 changes: 153 additions & 0 deletions
153
src/plugins/unified_field_list/common/utils/field_stats_utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { buildSearchParams } from './field_stats_utils'; | ||
|
||
describe('fieldStatsUtils', function () { | ||
describe('buildSearchParams()', () => { | ||
it('should work correctly for aggregations and a data view time field', () => { | ||
expect( | ||
buildSearchParams({ | ||
dataViewPattern: 'kibana_sample_data_logs', | ||
timeFieldName: 'timestamp', | ||
fromDate: '2022-12-05T23:00:00.000Z', | ||
toDate: '2023-01-05T09:33:05.359Z', | ||
dslQuery: { | ||
bool: { | ||
must: [], | ||
filter: [ | ||
{ | ||
match_phrase: { | ||
'geo.src': 'US', | ||
}, | ||
}, | ||
], | ||
should: [], | ||
must_not: [], | ||
}, | ||
}, | ||
runtimeMappings: { | ||
hour_of_day: { | ||
type: 'long', | ||
script: { | ||
source: "emit(doc['timestamp'].value.getHour());", | ||
}, | ||
}, | ||
}, | ||
aggs: { | ||
sample: { | ||
sampler: { | ||
shard_size: 5000, | ||
}, | ||
aggs: { | ||
sample_count: { | ||
value_count: { | ||
field: 'extension.keyword', | ||
}, | ||
}, | ||
top_values: { | ||
terms: { | ||
field: 'extension.keyword', | ||
size: 10, | ||
shard_size: 25, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
it('should work correctly for aggregations without a data view time field', () => { | ||
expect( | ||
buildSearchParams({ | ||
dataViewPattern: 'kibana_sample*', | ||
timeFieldName: '', | ||
fromDate: '2022-12-05T23:00:00.000Z', | ||
toDate: '2023-01-05T09:33:53.717Z', | ||
dslQuery: { | ||
bool: { | ||
must: [], | ||
filter: [ | ||
{ | ||
match_phrase: { | ||
'geo.src': 'US', | ||
}, | ||
}, | ||
], | ||
should: [], | ||
must_not: [], | ||
}, | ||
}, | ||
runtimeMappings: {}, | ||
aggs: { | ||
sample: { | ||
sampler: { | ||
shard_size: 5000, | ||
}, | ||
aggs: { | ||
sample_count: { | ||
value_count: { | ||
field: 'extension.keyword', | ||
}, | ||
}, | ||
top_values: { | ||
terms: { | ||
field: 'extension.keyword', | ||
size: 10, | ||
shard_size: 25, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
it('should work correctly for fetching field examples', () => { | ||
expect( | ||
buildSearchParams({ | ||
dataViewPattern: 'kibana_sample_data_logs', | ||
timeFieldName: 'timestamp', | ||
fromDate: '2022-12-05T23:00:00.000Z', | ||
toDate: '2023-01-05T09:35:24.109Z', | ||
dslQuery: { | ||
bool: { | ||
must: [], | ||
filter: [ | ||
{ | ||
match_phrase: { | ||
'geo.src': 'US', | ||
}, | ||
}, | ||
], | ||
should: [], | ||
must_not: [], | ||
}, | ||
}, | ||
runtimeMappings: { | ||
hour_of_day: { | ||
type: 'long', | ||
script: { | ||
source: "emit(doc['timestamp'].value.getHour());", | ||
}, | ||
}, | ||
}, | ||
fields: [ | ||
{ | ||
field: '_id', | ||
}, | ||
], | ||
size: 100, | ||
}) | ||
).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters