mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
# Backport This will backport the following commits from `main` to `8.6`: - [[Discover] Fix field stats for epoch time format (#148288)](https://github.com/elastic/kibana/pull/148288) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Julia Rechkunova","email":"julia.rechkunova@elastic.co"},"sourceCommit":{"committedDate":"2023-01-05T14:52:29Z","message":"[Discover] Fix field stats for epoch time format (#148288)\n\nCloses https://github.com/elastic/kibana/issues/148140\r\n\r\n## Summary\r\n\r\nThis PR fixes time format so it can work also for epoch.\r\n\r\nBefore:\r\n<img width=\"400\" alt=\"Screenshot 2023-01-03 at 12 33 17\"\r\nsrc=\"https://user-images.githubusercontent.com/1415710/210350243-b3ae1d1a-4c76-46e7-930f-0ca9835dc121.png\">\r\n\r\nAfter:\r\n<img width=\"400\" alt=\"Screenshot 2023-01-03 at 12 32 49\"\r\nsrc=\"https://user-images.githubusercontent.com/1415710/210350274-af80f558-6a32-4da6-9cb9-857a8cb3de70.png\">\r\n\r\nSample data for testing:\r\n```\r\nPUT test\r\nPUT test/_mapping\r\n{\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\": \"date\",\r\n \"format\": \"epoch_second\"\r\n },\r\n \"message\": {\r\n \"type\": \"keyword\"\r\n },\r\n \"bytes\": {\r\n \"type\": \"long\"\r\n }\r\n }\r\n}\r\n \r\nPOST test/_doc/1\r\n{\r\n \"timestamp\": 1669912088.9230318,\r\n \"message\": \"Message 1\",\r\n \"bytes\": 250\r\n}\r\nPOST test/_doc/2\r\n{\r\n \"timestamp\": 1669912088.9230319,\r\n \"message\": \"Message 2\",\r\n \"bytes\": 20\r\n}\r\n```","sha":"1b3769c86b683a3e1762f23b6f503479957044c6","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:DataDiscovery","backport:prev-minor","Feature:UnifiedFieldList","v8.7.0"],"number":148288,"url":"https://github.com/elastic/kibana/pull/148288","mergeCommit":{"message":"[Discover] Fix field stats for epoch time format (#148288)\n\nCloses https://github.com/elastic/kibana/issues/148140\r\n\r\n## Summary\r\n\r\nThis PR fixes time format so it can work also for epoch.\r\n\r\nBefore:\r\n<img width=\"400\" alt=\"Screenshot 2023-01-03 at 12 33 17\"\r\nsrc=\"https://user-images.githubusercontent.com/1415710/210350243-b3ae1d1a-4c76-46e7-930f-0ca9835dc121.png\">\r\n\r\nAfter:\r\n<img width=\"400\" alt=\"Screenshot 2023-01-03 at 12 32 49\"\r\nsrc=\"https://user-images.githubusercontent.com/1415710/210350274-af80f558-6a32-4da6-9cb9-857a8cb3de70.png\">\r\n\r\nSample data for testing:\r\n```\r\nPUT test\r\nPUT test/_mapping\r\n{\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\": \"date\",\r\n \"format\": \"epoch_second\"\r\n },\r\n \"message\": {\r\n \"type\": \"keyword\"\r\n },\r\n \"bytes\": {\r\n \"type\": \"long\"\r\n }\r\n }\r\n}\r\n \r\nPOST test/_doc/1\r\n{\r\n \"timestamp\": 1669912088.9230318,\r\n \"message\": \"Message 1\",\r\n \"bytes\": 250\r\n}\r\nPOST test/_doc/2\r\n{\r\n \"timestamp\": 1669912088.9230319,\r\n \"message\": \"Message 2\",\r\n \"bytes\": 20\r\n}\r\n```","sha":"1b3769c86b683a3e1762f23b6f503479957044c6"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/148288","number":148288,"mergeCommit":{"message":"[Discover] Fix field stats for epoch time format (#148288)\n\nCloses https://github.com/elastic/kibana/issues/148140\r\n\r\n## Summary\r\n\r\nThis PR fixes time format so it can work also for epoch.\r\n\r\nBefore:\r\n<img width=\"400\" alt=\"Screenshot 2023-01-03 at 12 33 17\"\r\nsrc=\"https://user-images.githubusercontent.com/1415710/210350243-b3ae1d1a-4c76-46e7-930f-0ca9835dc121.png\">\r\n\r\nAfter:\r\n<img width=\"400\" alt=\"Screenshot 2023-01-03 at 12 32 49\"\r\nsrc=\"https://user-images.githubusercontent.com/1415710/210350274-af80f558-6a32-4da6-9cb9-857a8cb3de70.png\">\r\n\r\nSample data for testing:\r\n```\r\nPUT test\r\nPUT test/_mapping\r\n{\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\": \"date\",\r\n \"format\": \"epoch_second\"\r\n },\r\n \"message\": {\r\n \"type\": \"keyword\"\r\n },\r\n \"bytes\": {\r\n \"type\": \"long\"\r\n }\r\n }\r\n}\r\n \r\nPOST test/_doc/1\r\n{\r\n \"timestamp\": 1669912088.9230318,\r\n \"message\": \"Message 1\",\r\n \"bytes\": 250\r\n}\r\nPOST test/_doc/2\r\n{\r\n \"timestamp\": 1669912088.9230319,\r\n \"message\": \"Message 2\",\r\n \"bytes\": 20\r\n}\r\n```","sha":"1b3769c86b683a3e1762f23b6f503479957044c6"}}]}] BACKPORT--> Co-authored-by: Julia Rechkunova <julia.rechkunova@elastic.co>
This commit is contained in:
parent
81da322425
commit
57f91bf76f
3 changed files with 338 additions and 0 deletions
184
src/plugins/unified_field_list/common/utils/__snapshots__/field_stats_utils.test.ts.snap
generated
Normal file
184
src/plugins/unified_field_list/common/utils/__snapshots__/field_stats_utils.test.ts.snap
generated
Normal file
|
@ -0,0 +1,184 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`fieldStatsUtils buildSearchParams() should work correctly for aggregations and a data view time field 1`] = `
|
||||
Object {
|
||||
"body": Object {
|
||||
"_source": undefined,
|
||||
"aggs": Object {
|
||||
"sample": Object {
|
||||
"aggs": Object {
|
||||
"sample_count": Object {
|
||||
"value_count": Object {
|
||||
"field": "extension.keyword",
|
||||
},
|
||||
},
|
||||
"top_values": Object {
|
||||
"terms": Object {
|
||||
"field": "extension.keyword",
|
||||
"shard_size": 25,
|
||||
"size": 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
"sampler": Object {
|
||||
"shard_size": 5000,
|
||||
},
|
||||
},
|
||||
},
|
||||
"fields": undefined,
|
||||
"query": Object {
|
||||
"bool": Object {
|
||||
"filter": Array [
|
||||
Object {
|
||||
"range": Object {
|
||||
"timestamp": Object {
|
||||
"format": "strict_date_optional_time",
|
||||
"gte": "2022-12-05T23:00:00.000Z",
|
||||
"lte": "2023-01-05T09:33:05.359Z",
|
||||
},
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"bool": Object {
|
||||
"filter": Array [
|
||||
Object {
|
||||
"match_phrase": Object {
|
||||
"geo.src": "US",
|
||||
},
|
||||
},
|
||||
],
|
||||
"must": Array [],
|
||||
"must_not": Array [],
|
||||
"should": Array [],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
"runtime_mappings": Object {
|
||||
"hour_of_day": Object {
|
||||
"script": Object {
|
||||
"source": "emit(doc['timestamp'].value.getHour());",
|
||||
},
|
||||
"type": "long",
|
||||
},
|
||||
},
|
||||
},
|
||||
"index": "kibana_sample_data_logs",
|
||||
"size": 0,
|
||||
"track_total_hits": true,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`fieldStatsUtils buildSearchParams() should work correctly for aggregations without a data view time field 1`] = `
|
||||
Object {
|
||||
"body": Object {
|
||||
"_source": undefined,
|
||||
"aggs": Object {
|
||||
"sample": Object {
|
||||
"aggs": Object {
|
||||
"sample_count": Object {
|
||||
"value_count": Object {
|
||||
"field": "extension.keyword",
|
||||
},
|
||||
},
|
||||
"top_values": Object {
|
||||
"terms": Object {
|
||||
"field": "extension.keyword",
|
||||
"shard_size": 25,
|
||||
"size": 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
"sampler": Object {
|
||||
"shard_size": 5000,
|
||||
},
|
||||
},
|
||||
},
|
||||
"fields": undefined,
|
||||
"query": Object {
|
||||
"bool": Object {
|
||||
"filter": Array [
|
||||
Object {
|
||||
"bool": Object {
|
||||
"filter": Array [
|
||||
Object {
|
||||
"match_phrase": Object {
|
||||
"geo.src": "US",
|
||||
},
|
||||
},
|
||||
],
|
||||
"must": Array [],
|
||||
"must_not": Array [],
|
||||
"should": Array [],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
"runtime_mappings": Object {},
|
||||
},
|
||||
"index": "kibana_sample*",
|
||||
"size": 0,
|
||||
"track_total_hits": true,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`fieldStatsUtils buildSearchParams() should work correctly for fetching field examples 1`] = `
|
||||
Object {
|
||||
"body": Object {
|
||||
"_source": false,
|
||||
"aggs": undefined,
|
||||
"fields": Array [
|
||||
Object {
|
||||
"field": "_id",
|
||||
},
|
||||
],
|
||||
"query": Object {
|
||||
"bool": Object {
|
||||
"filter": Array [
|
||||
Object {
|
||||
"range": Object {
|
||||
"timestamp": Object {
|
||||
"format": "strict_date_optional_time",
|
||||
"gte": "2022-12-05T23:00:00.000Z",
|
||||
"lte": "2023-01-05T09:35:24.109Z",
|
||||
},
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"bool": Object {
|
||||
"filter": Array [
|
||||
Object {
|
||||
"match_phrase": Object {
|
||||
"geo.src": "US",
|
||||
},
|
||||
},
|
||||
],
|
||||
"must": Array [],
|
||||
"must_not": Array [],
|
||||
"should": Array [],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"exists": Object {
|
||||
"field": "_id",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
"runtime_mappings": Object {
|
||||
"hour_of_day": Object {
|
||||
"script": Object {
|
||||
"source": "emit(doc['timestamp'].value.getHour());",
|
||||
},
|
||||
"type": "long",
|
||||
},
|
||||
},
|
||||
},
|
||||
"index": "kibana_sample_data_logs",
|
||||
"size": 100,
|
||||
"track_total_hits": true,
|
||||
}
|
||||
`;
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -55,6 +55,7 @@ export function buildSearchParams({
|
|||
[timeFieldName]: {
|
||||
gte: fromDate,
|
||||
lte: toDate,
|
||||
format: 'strict_date_optional_time',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue