Add Sampler & Diversified Sampler aggs to AggConfigs (#120135)

This commit is contained in:
Anton Dosov 2021-12-08 11:06:02 +01:00 committed by GitHub
parent 6fb732577f
commit 2e57f00253
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 798 additions and 38 deletions

View file

@ -62,6 +62,8 @@ export const getAggTypes = () => ({
{ name: BUCKET_TYPES.SIGNIFICANT_TERMS, fn: buckets.getSignificantTermsBucketAgg },
{ name: BUCKET_TYPES.GEOHASH_GRID, fn: buckets.getGeoHashBucketAgg },
{ name: BUCKET_TYPES.GEOTILE_GRID, fn: buckets.getGeoTitleBucketAgg },
{ name: BUCKET_TYPES.SAMPLER, fn: buckets.getSamplerBucketAgg },
{ name: BUCKET_TYPES.DIVERSIFIED_SAMPLER, fn: buckets.getDiversifiedSamplerBucketAgg },
],
});
@ -79,6 +81,8 @@ export const getAggTypesFunctions = () => [
buckets.aggDateHistogram,
buckets.aggTerms,
buckets.aggMultiTerms,
buckets.aggSampler,
buckets.aggDiversifiedSampler,
metrics.aggAvg,
metrics.aggBucketAvg,
metrics.aggBucketMax,

View file

@ -73,6 +73,8 @@ describe('Aggs service', () => {
"significant_terms",
"geohash_grid",
"geotile_grid",
"sampler",
"diversified_sampler",
"foo",
]
`);
@ -122,6 +124,8 @@ describe('Aggs service', () => {
"significant_terms",
"geohash_grid",
"geotile_grid",
"sampler",
"diversified_sampler",
]
`);
expect(bStart.types.getAll().metrics.map((t) => t(aggTypesDependencies).name))

View file

@ -19,4 +19,6 @@ export enum BUCKET_TYPES {
GEOHASH_GRID = 'geohash_grid',
GEOTILE_GRID = 'geotile_grid',
DATE_HISTOGRAM = 'date_histogram',
SAMPLER = 'sampler',
DIVERSIFIED_SAMPLER = 'diversified_sampler',
}

View file

@ -0,0 +1,62 @@
/*
* 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 { i18n } from '@kbn/i18n';
import { BucketAggType } from './bucket_agg_type';
import { BaseAggParams } from '../types';
import { aggDiversifiedSamplerFnName } from './diversified_sampler_fn';
export const DIVERSIFIED_SAMPLER_AGG_NAME = 'diversified_sampler';
const title = i18n.translate('data.search.aggs.buckets.diversifiedSamplerTitle', {
defaultMessage: 'Diversified sampler',
description: 'Diversified sampler aggregation title',
});
export interface AggParamsDiversifiedSampler extends BaseAggParams {
/**
* Is used to provide values used for de-duplication
*/
field: string;
/**
* Limits how many top-scoring documents are collected in the sample processed on each shard.
*/
shard_size?: number;
/**
* Limits how many documents are permitted per choice of de-duplicating value
*/
max_docs_per_value?: number;
}
/**
* Like the sampler aggregation this is a filtering aggregation used to limit any sub aggregations' processing to a sample of the top-scoring documents.
* The diversified_sampler aggregation adds the ability to limit the number of matches that share a common value.
*/
export const getDiversifiedSamplerBucketAgg = () =>
new BucketAggType({
name: DIVERSIFIED_SAMPLER_AGG_NAME,
title,
customLabels: false,
expressionName: aggDiversifiedSamplerFnName,
params: [
{
name: 'shard_size',
type: 'number',
},
{
name: 'max_docs_per_value',
type: 'number',
},
{
name: 'field',
type: 'field',
},
],
});

View file

@ -0,0 +1,58 @@
/*
* 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 { functionWrapper } from '../test_helpers';
import { aggDiversifiedSampler } from './diversified_sampler_fn';
describe('aggDiversifiedSampler', () => {
const fn = functionWrapper(aggDiversifiedSampler());
test('fills in defaults when only required args are provided', () => {
const actual = fn({ id: 'sampler', schema: 'bucket', field: 'author' });
expect(actual).toMatchInlineSnapshot(`
Object {
"type": "agg_type",
"value": Object {
"enabled": true,
"id": "sampler",
"params": Object {
"field": "author",
"max_docs_per_value": undefined,
"shard_size": undefined,
},
"schema": "bucket",
"type": "diversified_sampler",
},
}
`);
});
test('includes optional params when they are provided', () => {
const actual = fn({
id: 'sampler',
schema: 'bucket',
shard_size: 300,
field: 'author',
max_docs_per_value: 3,
});
expect(actual.value).toMatchInlineSnapshot(`
Object {
"enabled": true,
"id": "sampler",
"params": Object {
"field": "author",
"max_docs_per_value": 3,
"shard_size": 300,
},
"schema": "bucket",
"type": "diversified_sampler",
}
`);
});
});

View file

@ -0,0 +1,90 @@
/*
* 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 { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionFunctionArgs, AggExpressionType, BUCKET_TYPES } from '../';
import { DIVERSIFIED_SAMPLER_AGG_NAME } from './diversified_sampler';
export const aggDiversifiedSamplerFnName = 'aggDiversifiedSampler';
type Input = any;
type Arguments = AggExpressionFunctionArgs<typeof BUCKET_TYPES.DIVERSIFIED_SAMPLER>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggDiversifiedSamplerFnName,
Input,
Arguments,
Output
>;
export const aggDiversifiedSampler = (): FunctionDefinition => ({
name: aggDiversifiedSamplerFnName,
help: i18n.translate('data.search.aggs.function.buckets.diversifiedSampler.help', {
defaultMessage: 'Generates a serialized agg config for a Diversified sampler agg',
}),
type: 'agg_type',
args: {
id: {
types: ['string'],
help: i18n.translate('data.search.aggs.buckets.diversifiedSampler.id.help', {
defaultMessage: 'ID for this aggregation',
}),
},
enabled: {
types: ['boolean'],
default: true,
help: i18n.translate('data.search.aggs.buckets.diversifiedSampler.enabled.help', {
defaultMessage: 'Specifies whether this aggregation should be enabled',
}),
},
schema: {
types: ['string'],
help: i18n.translate('data.search.aggs.buckets.diversifiedSampler.schema.help', {
defaultMessage: 'Schema to use for this aggregation',
}),
},
shard_size: {
types: ['number'],
help: i18n.translate('data.search.aggs.buckets.diversifiedSampler.shardSize.help', {
defaultMessage:
'The shard_size parameter limits how many top-scoring documents are collected in the sample processed on each shard.',
}),
},
max_docs_per_value: {
types: ['number'],
help: i18n.translate('data.search.aggs.buckets.diversifiedSampler.maxDocsPerValue.help', {
defaultMessage:
'Limits how many documents are permitted per choice of de-duplicating value.',
}),
},
field: {
types: ['string'],
help: i18n.translate('data.search.aggs.buckets.diversifiedSampler.field.help', {
defaultMessage: 'Used to provide values used for de-duplication.',
}),
},
},
fn: (input, args) => {
const { id, enabled, schema, ...rest } = args;
return {
type: 'agg_type',
value: {
id,
enabled,
schema,
type: DIVERSIFIED_SAMPLER_AGG_NAME,
params: {
...rest,
},
},
};
},
});

View file

@ -38,3 +38,7 @@ export * from './terms_fn';
export * from './terms';
export * from './multi_terms_fn';
export * from './multi_terms';
export * from './sampler_fn';
export * from './sampler';
export * from './diversified_sampler_fn';
export * from './diversified_sampler';

View file

@ -0,0 +1,43 @@
/*
* 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 { i18n } from '@kbn/i18n';
import { BucketAggType } from './bucket_agg_type';
import { BaseAggParams } from '../types';
import { aggSamplerFnName } from './sampler_fn';
export const SAMPLER_AGG_NAME = 'sampler';
const title = i18n.translate('data.search.aggs.buckets.samplerTitle', {
defaultMessage: 'Sampler',
description: 'Sampler aggregation title',
});
export interface AggParamsSampler extends BaseAggParams {
/**
* Limits how many top-scoring documents are collected in the sample processed on each shard.
*/
shard_size?: number;
}
/**
* A filtering aggregation used to limit any sub aggregations' processing to a sample of the top-scoring documents.
*/
export const getSamplerBucketAgg = () =>
new BucketAggType({
name: SAMPLER_AGG_NAME,
title,
customLabels: false,
expressionName: aggSamplerFnName,
params: [
{
name: 'shard_size',
type: 'number',
},
],
});

View file

@ -0,0 +1,52 @@
/*
* 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 { functionWrapper } from '../test_helpers';
import { aggSampler } from './sampler_fn';
describe('aggSampler', () => {
const fn = functionWrapper(aggSampler());
test('fills in defaults when only required args are provided', () => {
const actual = fn({ id: 'sampler', schema: 'bucket' });
expect(actual).toMatchInlineSnapshot(`
Object {
"type": "agg_type",
"value": Object {
"enabled": true,
"id": "sampler",
"params": Object {
"shard_size": undefined,
},
"schema": "bucket",
"type": "sampler",
},
}
`);
});
test('includes optional params when they are provided', () => {
const actual = fn({
id: 'sampler',
schema: 'bucket',
shard_size: 300,
});
expect(actual.value).toMatchInlineSnapshot(`
Object {
"enabled": true,
"id": "sampler",
"params": Object {
"shard_size": 300,
},
"schema": "bucket",
"type": "sampler",
}
`);
});
});

View file

@ -0,0 +1,77 @@
/*
* 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 { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionFunctionArgs, AggExpressionType, BUCKET_TYPES } from '../';
import { SAMPLER_AGG_NAME } from './sampler';
export const aggSamplerFnName = 'aggSampler';
type Input = any;
type Arguments = AggExpressionFunctionArgs<typeof BUCKET_TYPES.SAMPLER>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggSamplerFnName,
Input,
Arguments,
Output
>;
export const aggSampler = (): FunctionDefinition => ({
name: aggSamplerFnName,
help: i18n.translate('data.search.aggs.function.buckets.sampler.help', {
defaultMessage: 'Generates a serialized agg config for a Sampler agg',
}),
type: 'agg_type',
args: {
id: {
types: ['string'],
help: i18n.translate('data.search.aggs.buckets.sampler.id.help', {
defaultMessage: 'ID for this aggregation',
}),
},
enabled: {
types: ['boolean'],
default: true,
help: i18n.translate('data.search.aggs.buckets.sampler.enabled.help', {
defaultMessage: 'Specifies whether this aggregation should be enabled',
}),
},
schema: {
types: ['string'],
help: i18n.translate('data.search.aggs.buckets.sampler.schema.help', {
defaultMessage: 'Schema to use for this aggregation',
}),
},
shard_size: {
types: ['number'],
help: i18n.translate('data.search.aggs.buckets.sampler.shardSize.help', {
defaultMessage:
'The shard_size parameter limits how many top-scoring documents are collected in the sample processed on each shard.',
}),
},
},
fn: (input, args) => {
const { id, enabled, schema, ...rest } = args;
return {
type: 'agg_type',
value: {
id,
enabled,
schema,
type: SAMPLER_AGG_NAME,
params: {
...rest,
},
},
};
},
});

View file

@ -90,6 +90,8 @@ import {
aggFilteredMetric,
aggSinglePercentile,
} from './';
import { AggParamsSampler } from './buckets/sampler';
import { AggParamsDiversifiedSampler } from './buckets/diversified_sampler';
export type { IAggConfig, AggConfigSerialized } from './agg_config';
export type { CreateAggConfigParams, IAggConfigs } from './agg_configs';
@ -166,6 +168,8 @@ export interface AggParamsMapping {
[BUCKET_TYPES.DATE_HISTOGRAM]: AggParamsDateHistogram;
[BUCKET_TYPES.TERMS]: AggParamsTerms;
[BUCKET_TYPES.MULTI_TERMS]: AggParamsMultiTerms;
[BUCKET_TYPES.SAMPLER]: AggParamsSampler;
[BUCKET_TYPES.DIVERSIFIED_SAMPLER]: AggParamsDiversifiedSampler;
[METRIC_TYPES.AVG]: AggParamsAvg;
[METRIC_TYPES.CARDINALITY]: AggParamsCardinality;
[METRIC_TYPES.COUNT]: BaseAggParams;

View file

@ -53,7 +53,7 @@ describe('AggsService - public', () => {
test('registers default agg types', () => {
service.setup(setupDeps);
const start = service.start(startDeps);
expect(start.types.getAll().buckets.length).toBe(12);
expect(start.types.getAll().buckets.length).toBe(14);
expect(start.types.getAll().metrics.length).toBe(23);
});
@ -69,7 +69,7 @@ describe('AggsService - public', () => {
);
const start = service.start(startDeps);
expect(start.types.getAll().buckets.length).toBe(13);
expect(start.types.getAll().buckets.length).toBe(15);
expect(start.types.getAll().buckets.some(({ name }) => name === 'foo')).toBe(true);
expect(start.types.getAll().metrics.length).toBe(24);
expect(start.types.getAll().metrics.some(({ name }) => name === 'bar')).toBe(true);

View file

@ -98,7 +98,14 @@ export const getHeatmapVisTypeDefinition = ({
}),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
{
group: AggGroupNames.Buckets,
@ -106,7 +113,14 @@ export const getHeatmapVisTypeDefinition = ({
title: i18n.translate('visTypeHeatmap.heatmap.groupTitle', { defaultMessage: 'Y-axis' }),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
{
group: AggGroupNames.Buckets,
@ -121,7 +135,14 @@ export const getHeatmapVisTypeDefinition = ({
}),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
],
},

View file

@ -86,7 +86,14 @@ export const createMetricVisTypeDefinition = (): VisTypeDefinition<VisParams> =>
}),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
],
},

View file

@ -87,7 +87,14 @@ export const samplePieVis = {
title: 'Split slices',
min: 0,
max: null,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
editor: false,
params: [],
},
@ -98,7 +105,14 @@ export const samplePieVis = {
mustBeFirst: true,
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
params: [
{
name: 'row',

View file

@ -80,7 +80,14 @@ export const getPieVisTypeDefinition = ({
}),
min: 0,
max: Infinity,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
{
group: AggGroupNames.Buckets,
@ -91,7 +98,14 @@ export const getPieVisTypeDefinition = ({
mustBeFirst: true,
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
],
},

View file

@ -62,7 +62,7 @@ export const tableVisTypeDefinition: VisTypeDefinition<TableVisParams> = {
title: i18n.translate('visTypeTable.tableVisEditorConfig.schemas.bucketTitle', {
defaultMessage: 'Split rows',
}),
aggFilter: ['!filter'],
aggFilter: ['!filter', '!sampler', '!diversified_sampler', '!multi_terms'],
},
{
group: AggGroupNames.Buckets,
@ -72,7 +72,7 @@ export const tableVisTypeDefinition: VisTypeDefinition<TableVisParams> = {
}),
min: 0,
max: 1,
aggFilter: ['!filter'],
aggFilter: ['!filter', '!sampler', '!diversified_sampler', '!multi_terms'],
},
],
},

View file

@ -132,7 +132,14 @@ export const gaugeVisTypeDefinition: VisTypeDefinition<GaugeVisParams> = {
}),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
],
},

View file

@ -96,7 +96,14 @@ export const goalVisTypeDefinition: VisTypeDefinition<GaugeVisParams> = {
}),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
],
},

View file

@ -625,7 +625,14 @@ export const getVis = (bucketType: string) => {
title: 'X-axis',
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
params: [],
},
{
@ -634,7 +641,14 @@ export const getVis = (bucketType: string) => {
title: 'Split series',
min: 0,
max: 3,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
params: [],
},
{
@ -643,7 +657,14 @@ export const getVis = (bucketType: string) => {
title: 'Split chart',
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
params: [
{
name: 'row',
@ -688,7 +709,14 @@ export const getVis = (bucketType: string) => {
title: 'X-axis',
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
params: [],
},
{
@ -697,7 +725,14 @@ export const getVis = (bucketType: string) => {
title: 'Split series',
min: 0,
max: 3,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
params: [],
},
{
@ -706,7 +741,14 @@ export const getVis = (bucketType: string) => {
title: 'Split chart',
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
params: [
{
name: 'row',
@ -722,7 +764,14 @@ export const getVis = (bucketType: string) => {
title: 'X-axis',
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
params: [],
},
{
@ -731,7 +780,14 @@ export const getVis = (bucketType: string) => {
title: 'Split series',
min: 0,
max: 3,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
params: [],
},
{
@ -740,7 +796,14 @@ export const getVis = (bucketType: string) => {
title: 'Split chart',
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
params: [
{
name: 'row',

View file

@ -149,7 +149,14 @@ export const sampleAreaVis = {
title: 'X-axis',
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
editor: false,
params: [],
},
@ -159,7 +166,14 @@ export const sampleAreaVis = {
title: 'Split series',
min: 0,
max: 3,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
editor: false,
params: [],
},
@ -169,7 +183,14 @@ export const sampleAreaVis = {
title: 'Split chart',
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
params: [
{
name: 'row',

View file

@ -157,7 +157,14 @@ export const areaVisTypeDefinition = {
}),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
{
group: AggGroupNames.Buckets,
@ -167,7 +174,14 @@ export const areaVisTypeDefinition = {
}),
min: 0,
max: 3,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
{
group: AggGroupNames.Buckets,
@ -177,7 +191,14 @@ export const areaVisTypeDefinition = {
}),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
],
},

View file

@ -160,7 +160,14 @@ export const histogramVisTypeDefinition = {
}),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
{
group: AggGroupNames.Buckets,
@ -170,7 +177,14 @@ export const histogramVisTypeDefinition = {
}),
min: 0,
max: 3,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
{
group: AggGroupNames.Buckets,
@ -180,7 +194,14 @@ export const histogramVisTypeDefinition = {
}),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
],
},

View file

@ -159,7 +159,14 @@ export const horizontalBarVisTypeDefinition = {
}),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
{
group: AggGroupNames.Buckets,
@ -169,7 +176,14 @@ export const horizontalBarVisTypeDefinition = {
}),
min: 0,
max: 3,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
{
group: AggGroupNames.Buckets,
@ -179,7 +193,14 @@ export const horizontalBarVisTypeDefinition = {
}),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
],
},

View file

@ -151,7 +151,14 @@ export const lineVisTypeDefinition = {
title: i18n.translate('visTypeXy.line.segmentTitle', { defaultMessage: 'X-axis' }),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
{
group: AggGroupNames.Buckets,
@ -161,7 +168,14 @@ export const lineVisTypeDefinition = {
}),
min: 0,
max: 3,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
{
group: AggGroupNames.Buckets,
@ -171,7 +185,14 @@ export const lineVisTypeDefinition = {
}),
min: 0,
max: 1,
aggFilter: ['!geohash_grid', '!geotile_grid', '!filter', '!multi_terms'],
aggFilter: [
'!geohash_grid',
'!geotile_grid',
'!filter',
'!sampler',
'!diversified_sampler',
'!multi_terms',
],
},
],
},

View file

@ -0,0 +1,121 @@
/*
* 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 expect from '@kbn/expect';
import { ExpectExpression, expectExpressionProvider } from './helpers';
import { FtrProviderContext } from '../../../functional/ftr_provider_context';
export default function ({
getService,
updateBaselines,
}: FtrProviderContext & { updateBaselines: boolean }) {
let expectExpression: ExpectExpression;
describe('esaggs_sampler', () => {
before(() => {
expectExpression = expectExpressionProvider({ getService, updateBaselines });
});
const timeRange = {
from: '2015-09-21T00:00:00Z',
to: '2015-09-22T00:00:00Z',
};
describe('aggSampler', () => {
it('can execute aggSampler', async () => {
const expression = `
kibana_context timeRange={timerange from='${timeRange.from}' to='${timeRange.to}'}
| esaggs index={indexPatternLoad id='logstash-*'}
aggs={aggSampler id="0" enabled=true schema="bucket"}
aggs={aggAvg id="1" enabled=true schema="metric" field="bytes"}
`;
const result = await expectExpression('sampler', expression).getResponse();
expect(result.columns.length).to.be(2);
const samplerColumn = result.columns[0];
expect(samplerColumn.name).to.be('sampler');
expect(samplerColumn.meta.sourceParams.params).to.eql({});
expect(result.rows.length).to.be(1);
expect(Object.keys(result.rows[0]).length).to.be(1);
const resultFromSample = result.rows[0]['col-1-1']; // check that sampler bucket doesn't produce columns
expect(typeof resultFromSample).to.be('number');
expect(resultFromSample).to.greaterThan(0); // can't check exact metric using sample
});
it('can execute aggSampler with custom shard_size', async () => {
const expression = `
kibana_context timeRange={timerange from='${timeRange.from}' to='${timeRange.to}'}
| esaggs index={indexPatternLoad id='logstash-*'}
aggs={aggSampler id="0" enabled=true schema="bucket" shard_size=20}
aggs={aggAvg id="1" enabled=true schema="metric" field="bytes"}
`;
const result = await expectExpression('sampler', expression).getResponse();
expect(result.columns.length).to.be(2);
const samplerColumn = result.columns[0];
expect(samplerColumn.name).to.be('sampler');
expect(samplerColumn.meta.sourceParams.params).to.eql({ shard_size: 20 });
expect(result.rows.length).to.be(1);
expect(Object.keys(result.rows[0]).length).to.be(1); // check that sampler bucket doesn't produce columns
const resultFromSample = result.rows[0]['col-1-1'];
expect(typeof resultFromSample).to.be('number');
expect(resultFromSample).to.greaterThan(0); // can't check exact metric using sample
});
});
describe('aggDiversifiedSampler', () => {
it('can execute aggDiversifiedSampler', async () => {
const expression = `
kibana_context timeRange={timerange from='${timeRange.from}' to='${timeRange.to}'}
| esaggs index={indexPatternLoad id='logstash-*'}
aggs={aggDiversifiedSampler id="0" enabled=true schema="bucket" field="extension.raw"}
aggs={aggAvg id="1" enabled=true schema="metric" field="bytes"}
`;
const result = await expectExpression('sampler', expression).getResponse();
expect(result.columns.length).to.be(2);
const samplerColumn = result.columns[0];
expect(samplerColumn.name).to.be('diversified_sampler');
expect(samplerColumn.meta.sourceParams.params).to.eql({ field: 'extension.raw' });
expect(result.rows.length).to.be(1);
expect(Object.keys(result.rows[0]).length).to.be(1);
const resultFromSample = result.rows[0]['col-1-1']; // check that sampler bucket doesn't produce columns
expect(typeof resultFromSample).to.be('number');
expect(resultFromSample).to.greaterThan(0); // can't check exact metric using sample
});
it('can execute aggSampler with custom shard_size and max_docs_per_value', async () => {
const expression = `
kibana_context timeRange={timerange from='${timeRange.from}' to='${timeRange.to}'}
| esaggs index={indexPatternLoad id='logstash-*'}
aggs={aggDiversifiedSampler id="0" enabled=true schema="bucket" field="extension.raw" shard_size=20 max_docs_per_value=3}
aggs={aggAvg id="1" enabled=true schema="metric" field="bytes"}
`;
const result = await expectExpression('sampler', expression).getResponse();
expect(result.columns.length).to.be(2);
const samplerColumn = result.columns[0];
expect(samplerColumn.name).to.be('diversified_sampler');
expect(samplerColumn.meta.sourceParams.params).to.eql({
field: 'extension.raw',
max_docs_per_value: 3,
shard_size: 20,
});
expect(result.rows.length).to.be(1);
expect(Object.keys(result.rows[0]).length).to.be(1); // check that sampler bucket doesn't produce columns
const resultFromSample = result.rows[0]['col-1-1'];
expect(typeof resultFromSample).to.be('number');
expect(resultFromSample).to.greaterThan(0); // can't check exact metric using sample
});
});
});
}

View file

@ -44,5 +44,6 @@ export default function ({ getService, getPageObjects, loadTestFile }: FtrProvid
loadTestFile(require.resolve('./esaggs'));
loadTestFile(require.resolve('./esaggs_timeshift'));
loadTestFile(require.resolve('./esaggs_multiterms'));
loadTestFile(require.resolve('./esaggs_sampler'));
});
}