Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Fix field stats for epoch time format #148288

Merged
merged 7 commits into from Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

153 changes: 153 additions & 0 deletions src/plugins/unified_field_list/common/utils/field_stats_utils.test.ts
@@ -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();
});
});
});
Expand Up @@ -55,6 +55,7 @@ export function buildSearchParams({
[timeFieldName]: {
gte: fromDate,
lte: toDate,
format: 'strict_date_optional_time',
},
},
},
Expand Down