[data.search][data.indexPatterns] Expose esaggs + indexPatternLoad on the server. (#84590)

This commit is contained in:
Luke Elmers 2020-12-03 08:28:50 -07:00 committed by GitHub
parent eb0569b1ff
commit d2fc976b09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
122 changed files with 1652 additions and 384 deletions

View file

@ -89,7 +89,7 @@
| [SavedQueryService](./kibana-plugin-plugins-data-public.savedqueryservice.md) | |
| [SearchError](./kibana-plugin-plugins-data-public.searcherror.md) | |
| [SearchInterceptorDeps](./kibana-plugin-plugins-data-public.searchinterceptordeps.md) | |
| [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.md) | Provide info about current search session to be stored in backgroundSearch saved object |
| [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.md) | Provide info about current search session to be stored in backgroundSearch saved object |
| [SearchSourceFields](./kibana-plugin-plugins-data-public.searchsourcefields.md) | search source fields |
| [TabbedAggColumn](./kibana-plugin-plugins-data-public.tabbedaggcolumn.md) | \* |
| [TabbedTable](./kibana-plugin-plugins-data-public.tabbedtable.md) | \* |

View file

@ -1,6 +1,6 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.md) &gt; [getName](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.getname.md)
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.md) &gt; [getName](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.getname.md)
## SearchSessionInfoProvider.getName property

View file

@ -1,6 +1,6 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.md) &gt; [getUrlGeneratorData](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.geturlgeneratordata.md)
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.md) &gt; [getUrlGeneratorData](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.geturlgeneratordata.md)
## SearchSessionInfoProvider.getUrlGeneratorData property

View file

@ -1,6 +1,6 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.md)
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.md)
## SearchSessionInfoProvider interface
@ -16,6 +16,6 @@ export interface SearchSessionInfoProvider<ID extends UrlGeneratorId = UrlGenera
| Property | Type | Description |
| --- | --- | --- |
| [getName](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.getname.md) | <code>() =&gt; Promise&lt;string&gt;</code> | User-facing name of the session. e.g. will be displayed in background sessions management list |
| [getUrlGeneratorData](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.geturlgeneratordata.md) | <code>() =&gt; Promise&lt;{</code><br/><code> urlGeneratorId: ID;</code><br/><code> initialState: UrlGeneratorStateMapping[ID]['State'];</code><br/><code> restoreState: UrlGeneratorStateMapping[ID]['State'];</code><br/><code> }&gt;</code> | |
| [getName](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.getname.md) | <code>() =&gt; Promise&lt;string&gt;</code> | User-facing name of the session. e.g. will be displayed in background sessions management list |
| [getUrlGeneratorData](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.geturlgeneratordata.md) | <code>() =&gt; Promise&lt;{</code><br/><code> urlGeneratorId: ID;</code><br/><code> initialState: UrlGeneratorStateMapping[ID]['State'];</code><br/><code> restoreState: UrlGeneratorStateMapping[ID]['State'];</code><br/><code> }&gt;</code> | |

View file

@ -13,7 +13,7 @@ getFields(): {
type?: string | undefined;
query?: import("../..").Query | undefined;
filter?: Filter | Filter[] | (() => Filter | Filter[] | undefined) | undefined;
sort?: Record<string, import("./types").SortDirection | import("./types").SortDirectionNumeric> | Record<string, import("./types").SortDirection | import("./types").SortDirectionNumeric>[] | undefined;
sort?: Record<string, import("./types").SortDirectionNumeric | import("./types").SortDirection> | Record<string, import("./types").SortDirectionNumeric | import("./types").SortDirection>[] | undefined;
highlight?: any;
highlightAll?: boolean | undefined;
aggs?: any;
@ -35,7 +35,7 @@ getFields(): {
type?: string | undefined;
query?: import("../..").Query | undefined;
filter?: Filter | Filter[] | (() => Filter | Filter[] | undefined) | undefined;
sort?: Record<string, import("./types").SortDirection | import("./types").SortDirectionNumeric> | Record<string, import("./types").SortDirection | import("./types").SortDirectionNumeric>[] | undefined;
sort?: Record<string, import("./types").SortDirectionNumeric | import("./types").SortDirection> | Record<string, import("./types").SortDirectionNumeric | import("./types").SortDirection>[] | undefined;
highlight?: any;
highlightAll?: boolean | undefined;
aggs?: any;

View file

@ -14,6 +14,6 @@ export declare class IndexPatternsService implements Plugin<void, IndexPatternsS
| Method | Modifiers | Description |
| --- | --- | --- |
| [setup(core)](./kibana-plugin-plugins-data-server.indexpatternsservice.setup.md) | | |
| [setup(core, { expressions })](./kibana-plugin-plugins-data-server.indexpatternsservice.setup.md) | | |
| [start(core, { fieldFormats, logger })](./kibana-plugin-plugins-data-server.indexpatternsservice.start.md) | | |

View file

@ -7,14 +7,15 @@
<b>Signature:</b>
```typescript
setup(core: CoreSetup): void;
setup(core: CoreSetup<DataPluginStartDependencies, DataPluginStart>, { expressions }: IndexPatternsServiceSetupDeps): void;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| core | <code>CoreSetup</code> | |
| core | <code>CoreSetup&lt;DataPluginStartDependencies, DataPluginStart&gt;</code> | |
| { expressions } | <code>IndexPatternsServiceSetupDeps</code> | |
<b>Returns:</b>

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) &gt; [ExecutionContext](./kibana-plugin-plugins-expressions-public.executioncontext.md) &gt; [getKibanaRequest](./kibana-plugin-plugins-expressions-public.executioncontext.getkibanarequest.md)
## ExecutionContext.getKibanaRequest property
Getter to retrieve the `KibanaRequest` object inside an expression function. Useful for functions which are running on the server and need to perform operations that are scoped to a specific user.
<b>Signature:</b>
```typescript
getKibanaRequest?: () => KibanaRequest;
```

View file

@ -17,6 +17,7 @@ export interface ExecutionContext<InspectorAdapters extends Adapters = Adapters,
| Property | Type | Description |
| --- | --- | --- |
| [abortSignal](./kibana-plugin-plugins-expressions-public.executioncontext.abortsignal.md) | <code>AbortSignal</code> | Adds ability to abort current execution. |
| [getKibanaRequest](./kibana-plugin-plugins-expressions-public.executioncontext.getkibanarequest.md) | <code>() =&gt; KibanaRequest</code> | Getter to retrieve the <code>KibanaRequest</code> object inside an expression function. Useful for functions which are running on the server and need to perform operations that are scoped to a specific user. |
| [getSavedObject](./kibana-plugin-plugins-expressions-public.executioncontext.getsavedobject.md) | <code>&lt;T extends SavedObjectAttributes = SavedObjectAttributes&gt;(type: string, id: string) =&gt; Promise&lt;SavedObject&lt;T&gt;&gt;</code> | Allows to fetch saved objects from ElasticSearch. In browser <code>getSavedObject</code> function is provided automatically by the Expressions plugin. On the server the caller of the expression has to provide this context function. The reason is because on the browser we always know the user who tries to fetch a saved object, thus saved object client is scoped automatically to that user. However, on the server we can scope that saved object client to any user, or even not scope it at all and execute it as an "internal" user. |
| [getSearchContext](./kibana-plugin-plugins-expressions-public.executioncontext.getsearchcontext.md) | <code>() =&gt; ExecutionContextSearch</code> | Get search context of the expression. |
| [getSearchSessionId](./kibana-plugin-plugins-expressions-public.executioncontext.getsearchsessionid.md) | <code>() =&gt; string &#124; undefined</code> | Search context in which expression should operate. |

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-expressions-server](./kibana-plugin-plugins-expressions-server.md) &gt; [ExecutionContext](./kibana-plugin-plugins-expressions-server.executioncontext.md) &gt; [getKibanaRequest](./kibana-plugin-plugins-expressions-server.executioncontext.getkibanarequest.md)
## ExecutionContext.getKibanaRequest property
Getter to retrieve the `KibanaRequest` object inside an expression function. Useful for functions which are running on the server and need to perform operations that are scoped to a specific user.
<b>Signature:</b>
```typescript
getKibanaRequest?: () => KibanaRequest;
```

View file

@ -17,6 +17,7 @@ export interface ExecutionContext<InspectorAdapters extends Adapters = Adapters,
| Property | Type | Description |
| --- | --- | --- |
| [abortSignal](./kibana-plugin-plugins-expressions-server.executioncontext.abortsignal.md) | <code>AbortSignal</code> | Adds ability to abort current execution. |
| [getKibanaRequest](./kibana-plugin-plugins-expressions-server.executioncontext.getkibanarequest.md) | <code>() =&gt; KibanaRequest</code> | Getter to retrieve the <code>KibanaRequest</code> object inside an expression function. Useful for functions which are running on the server and need to perform operations that are scoped to a specific user. |
| [getSavedObject](./kibana-plugin-plugins-expressions-server.executioncontext.getsavedobject.md) | <code>&lt;T extends SavedObjectAttributes = SavedObjectAttributes&gt;(type: string, id: string) =&gt; Promise&lt;SavedObject&lt;T&gt;&gt;</code> | Allows to fetch saved objects from ElasticSearch. In browser <code>getSavedObject</code> function is provided automatically by the Expressions plugin. On the server the caller of the expression has to provide this context function. The reason is because on the browser we always know the user who tries to fetch a saved object, thus saved object client is scoped automatically to that user. However, on the server we can scope that saved object client to any user, or even not scope it at all and execute it as an "internal" user. |
| [getSearchContext](./kibana-plugin-plugins-expressions-server.executioncontext.getsearchcontext.md) | <code>() =&gt; ExecutionContextSearch</code> | Get search context of the expression. |
| [getSearchSessionId](./kibana-plugin-plugins-expressions-server.executioncontext.getsearchsessionid.md) | <code>() =&gt; string &#124; undefined</code> | Search context in which expression should operate. |

View file

@ -27,11 +27,10 @@ import {
FieldFormatInstanceType,
FieldFormatId,
IFieldFormatMetaParams,
IFieldFormat,
} from './types';
import { baseFormatters } from './constants/base_formatters';
import { FieldFormat } from './field_format';
import { SerializedFieldFormat } from '../../../expressions/common/types';
import { FormatFactory } from './utils';
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '../kbn_field_types/types';
import { UI_SETTINGS } from '../constants';
import { FieldFormatNotFoundError } from '../field_formats';
@ -42,7 +41,7 @@ export class FieldFormatsRegistry {
protected metaParamsOptions: Record<string, any> = {};
protected getConfig?: FieldFormatsGetConfigFn;
// overriden on the public contract
public deserialize: (mapping: SerializedFieldFormat) => IFieldFormat = () => {
public deserialize: FormatFactory = () => {
return new (FieldFormat.from(identity))();
};

View file

@ -17,24 +17,4 @@
* under the License.
*/
import { Datatable, ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { KibanaContext } from './kibana_context_type';
type Input = KibanaContext | null;
type Output = Promise<Datatable>;
interface Arguments {
index: string;
metricsAtAllLevels: boolean;
partialRows: boolean;
includeFormatHints: boolean;
aggConfigs: string;
timeFields?: string[];
}
export type EsaggsExpressionFunctionDefinition = ExpressionFunctionDefinition<
'esaggs',
Input,
Arguments,
Output
>;
export * from './load_index_pattern';

View file

@ -0,0 +1,65 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { IndexPatternsContract } from '../index_patterns';
import { IndexPatternSpec } from '..';
const name = 'indexPatternLoad';
type Input = null;
type Output = Promise<{ type: 'index_pattern'; value: IndexPatternSpec }>;
interface Arguments {
id: string;
}
/** @internal */
export interface IndexPatternLoadStartDependencies {
indexPatterns: IndexPatternsContract;
}
export type IndexPatternLoadExpressionFunctionDefinition = ExpressionFunctionDefinition<
typeof name,
Input,
Arguments,
Output
>;
export const getIndexPatternLoadMeta = (): Omit<
IndexPatternLoadExpressionFunctionDefinition,
'fn'
> => ({
name,
type: 'index_pattern',
inputTypes: ['null'],
help: i18n.translate('data.functions.indexPatternLoad.help', {
defaultMessage: 'Loads an index pattern',
}),
args: {
id: {
types: ['string'],
required: true,
help: i18n.translate('data.functions.indexPatternLoad.id.help', {
defaultMessage: 'index pattern id to load',
}),
},
},
});

View file

@ -33,6 +33,7 @@ describe('AggType Class', () => {
test('assigns the config value to itself', () => {
const config: AggTypeConfig = {
name: 'name',
expressionName: 'aggName',
title: 'title',
};
@ -48,6 +49,7 @@ describe('AggType Class', () => {
const aggConfig = {} as IAggConfig;
const config: AggTypeConfig = {
name: 'name',
expressionName: 'aggName',
title: 'title',
makeLabel,
};
@ -65,6 +67,7 @@ describe('AggType Class', () => {
const aggType = new AggType({
name: 'name',
expressionName: 'aggName',
title: 'title',
getResponseAggs: testConfig,
getRequestAggs: testConfig,
@ -78,6 +81,7 @@ describe('AggType Class', () => {
const aggConfig = {} as IAggConfig;
const aggType = new AggType({
name: 'name',
expressionName: 'aggName',
title: 'title',
});
const responseAggs = aggType.getRequestAggs(aggConfig);
@ -90,6 +94,7 @@ describe('AggType Class', () => {
test('defaults to AggParams object with JSON param', () => {
const aggType = new AggType({
name: 'smart agg',
expressionName: 'aggSmart',
title: 'title',
});
@ -102,6 +107,7 @@ describe('AggType Class', () => {
test('disables json param', () => {
const aggType = new AggType({
name: 'name',
expressionName: 'aggName',
title: 'title',
json: false,
});
@ -113,6 +119,7 @@ describe('AggType Class', () => {
test('can disable customLabel', () => {
const aggType = new AggType({
name: 'smart agg',
expressionName: 'aggSmart',
title: 'title',
customLabels: false,
});
@ -127,6 +134,7 @@ describe('AggType Class', () => {
const aggType = new AggType({
name: 'bucketeer',
expressionName: 'aggBucketeer',
title: 'title',
params,
});
@ -153,6 +161,7 @@ describe('AggType Class', () => {
} as unknown) as IAggConfig;
const aggType = new AggType({
name: 'name',
expressionName: 'aggName',
title: 'title',
});
expect(aggType.getSerializedFormat(aggConfig)).toMatchInlineSnapshot(`
@ -168,6 +177,7 @@ describe('AggType Class', () => {
} as unknown) as IAggConfig;
const aggType = new AggType({
name: 'name',
expressionName: 'aggName',
title: 'title',
});
expect(aggType.getSerializedFormat(aggConfig)).toMatchInlineSnapshot(`Object {}`);
@ -186,6 +196,7 @@ describe('AggType Class', () => {
const getSerializedFormat = jest.fn().mockReturnValue({ id: 'hello' });
const aggType = new AggType({
name: 'name',
expressionName: 'aggName',
title: 'title',
getSerializedFormat,
});

View file

@ -39,7 +39,7 @@ export interface AggTypeConfig<
createFilter?: (aggConfig: TAggConfig, key: any, params?: any) => any;
type?: string;
dslName?: string;
expressionName?: string;
expressionName: string;
makeLabel?: ((aggConfig: TAggConfig) => string) | (() => string);
ordered?: any;
hasNoDsl?: boolean;
@ -90,12 +90,11 @@ export class AggType<
dslName: string;
/**
* the name of the expression function that this aggType represents.
* TODO: this should probably be a required field.
*
* @property name
* @type {string}
*/
expressionName?: string;
expressionName: string;
/**
* the user friendly name that will be shown in the ui for this aggType
*

View file

@ -27,6 +27,7 @@ import { intervalOptions, autoInterval, isAutoInterval } from './_interval_optio
import { createFilterDateHistogram } from './create_filter/date_histogram';
import { BucketAggType, IBucketAggConfig } from './bucket_agg_type';
import { BUCKET_TYPES } from './bucket_agg_types';
import { aggDateHistogramFnName } from './date_histogram_fn';
import { ExtendedBounds } from './lib/extended_bounds';
import { TimeBuckets } from './lib/time_buckets';
@ -87,6 +88,7 @@ export const getDateHistogramBucketAgg = ({
}: DateHistogramBucketAggDependencies) =>
new BucketAggType<IBucketDateHistogramAggConfig>({
name: BUCKET_TYPES.DATE_HISTOGRAM,
expressionName: aggDateHistogramFnName,
title: i18n.translate('data.search.aggs.buckets.dateHistogramTitle', {
defaultMessage: 'Date Histogram',
}),

View file

@ -23,7 +23,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, BUCKET_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggDateHistogram';
export const aggDateHistogramFnName = 'aggDateHistogram';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.DATE_HISTOGRAM>;
@ -31,10 +31,15 @@ type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.DATE_HISTOGRAM>;
type Arguments = Assign<AggArgs, { timeRange?: string; extended_bounds?: string }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggDateHistogramFnName,
Input,
Arguments,
Output
>;
export const aggDateHistogram = (): FunctionDefinition => ({
name: fnName,
name: aggDateHistogramFnName,
help: i18n.translate('data.search.aggs.function.buckets.dateHistogram.help', {
defaultMessage: 'Generates a serialized agg config for a Histogram agg',
}),

View file

@ -74,6 +74,31 @@ describe('date_range params', () => {
);
};
test('produces the expected expression ast', () => {
const aggConfigs = getAggConfigs();
const dateRange = aggConfigs.aggs[0];
expect(dateRange.toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"enabled": Array [
true,
],
"id": Array [
"date_range",
],
"ranges": Array [
"[{\\"from\\":\\"now-1w/w\\",\\"to\\":\\"now\\"}]",
],
"schema": Array [
"buckets",
],
},
"function": "aggDateRange",
"type": "function",
}
`);
});
describe('getKey', () => {
test('should return object', () => {
const aggConfigs = getAggConfigs();

View file

@ -24,6 +24,7 @@ import { i18n } from '@kbn/i18n';
import { BUCKET_TYPES } from './bucket_agg_types';
import { BucketAggType, IBucketAggConfig } from './bucket_agg_type';
import { createFilterDateRange } from './create_filter/date_range';
import { aggDateRangeFnName } from './date_range_fn';
import { DateRangeKey } from './lib/date_range';
import { KBN_FIELD_TYPES } from '../../../../common/kbn_field_types/types';
@ -50,6 +51,7 @@ export const getDateRangeBucketAgg = ({
}: DateRangeBucketAggDependencies) =>
new BucketAggType({
name: BUCKET_TYPES.DATE_RANGE,
expressionName: aggDateRangeFnName,
title: dateRangeTitle,
createFilter: createFilterDateRange,
getKey({ from, to }): DateRangeKey {

View file

@ -23,7 +23,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, BUCKET_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggDateRange';
export const aggDateRangeFnName = 'aggDateRange';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.DATE_RANGE>;
@ -31,10 +31,15 @@ type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.DATE_RANGE>;
type Arguments = Assign<AggArgs, { ranges?: string }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggDateRangeFnName,
Input,
Arguments,
Output
>;
export const aggDateRange = (): FunctionDefinition => ({
name: fnName,
name: aggDateRangeFnName,
help: i18n.translate('data.search.aggs.function.buckets.dateRange.help', {
defaultMessage: 'Generates a serialized agg config for a Date Range agg',
}),

View file

@ -21,6 +21,7 @@ import { i18n } from '@kbn/i18n';
import { BucketAggType } from './bucket_agg_type';
import { BUCKET_TYPES } from './bucket_agg_types';
import { GeoBoundingBox } from './lib/geo_point';
import { aggFilterFnName } from './filter_fn';
import { BaseAggParams } from '../types';
const filterTitle = i18n.translate('data.search.aggs.buckets.filterTitle', {
@ -34,6 +35,7 @@ export interface AggParamsFilter extends BaseAggParams {
export const getFilterBucketAgg = () =>
new BucketAggType({
name: BUCKET_TYPES.FILTER,
expressionName: aggFilterFnName,
title: filterTitle,
makeLabel: () => filterTitle,
params: [

View file

@ -23,7 +23,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, BUCKET_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggFilter';
export const aggFilterFnName = 'aggFilter';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.FILTER>;
@ -31,10 +31,15 @@ type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.FILTER>;
type Arguments = Assign<AggArgs, { geo_bounding_box?: string }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggFilterFnName,
Input,
Arguments,
Output
>;
export const aggFilter = (): FunctionDefinition => ({
name: fnName,
name: aggFilterFnName,
help: i18n.translate('data.search.aggs.function.buckets.filter.help', {
defaultMessage: 'Generates a serialized agg config for a Filter agg',
}),

View file

@ -74,6 +74,33 @@ describe('Filters Agg', () => {
},
});
test('produces the expected expression ast', () => {
const aggConfigs = getAggConfigs({
filters: [
generateFilter('a', 'lucene', 'foo'),
generateFilter('b', 'lucene', 'status:200'),
generateFilter('c', 'lucene', 'status:[400 TO 499] AND (foo OR bar)'),
],
});
expect(aggConfigs.aggs[0].toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"enabled": Array [
true,
],
"filters": Array [
"[{\\"label\\":\\"a\\",\\"input\\":{\\"language\\":\\"lucene\\",\\"query\\":\\"foo\\"}},{\\"label\\":\\"b\\",\\"input\\":{\\"language\\":\\"lucene\\",\\"query\\":\\"status:200\\"}},{\\"label\\":\\"c\\",\\"input\\":{\\"language\\":\\"lucene\\",\\"query\\":\\"status:[400 TO 499] AND (foo OR bar)\\"}}]",
],
"id": Array [
"test",
],
},
"function": "aggFilters",
"type": "function",
}
`);
});
describe('using Lucene', () => {
test('works with lucene filters', () => {
const aggConfigs = getAggConfigs({

View file

@ -24,6 +24,7 @@ import { createFilterFilters } from './create_filter/filters';
import { toAngularJSON } from '../utils';
import { BucketAggType } from './bucket_agg_type';
import { BUCKET_TYPES } from './bucket_agg_types';
import { aggFiltersFnName } from './filters_fn';
import { getEsQueryConfig, buildEsQuery, Query, UI_SETTINGS } from '../../../../common';
import { BaseAggParams } from '../types';
@ -53,6 +54,7 @@ export interface AggParamsFilters extends Omit<BaseAggParams, 'customLabel'> {
export const getFiltersBucketAgg = ({ getConfig }: FiltersBucketAggDependencies) =>
new BucketAggType({
name: BUCKET_TYPES.FILTERS,
expressionName: aggFiltersFnName,
title: filtersTitle,
createFilter: createFilterFilters,
customLabels: false,

View file

@ -23,7 +23,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, BUCKET_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggFilters';
export const aggFiltersFnName = 'aggFilters';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.FILTERS>;
@ -31,10 +31,15 @@ type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.FILTERS>;
type Arguments = Assign<AggArgs, { filters?: string }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggFiltersFnName,
Input,
Arguments,
Output
>;
export const aggFilters = (): FunctionDefinition => ({
name: fnName,
name: aggFiltersFnName,
help: i18n.translate('data.search.aggs.function.buckets.filters.help', {
defaultMessage: 'Generates a serialized agg config for a Filter agg',
}),

View file

@ -87,6 +87,42 @@ describe('Geohash Agg', () => {
});
});
test('produces the expected expression ast', () => {
const aggConfigs = getAggConfigs();
expect(aggConfigs.aggs[0].toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"autoPrecision": Array [
true,
],
"enabled": Array [
true,
],
"field": Array [
"location",
],
"id": Array [
"geohash_grid",
],
"isFilteredByCollar": Array [
true,
],
"precision": Array [
2,
],
"schema": Array [
"segment",
],
"useGeocentroid": Array [
true,
],
},
"function": "aggGeoHash",
"type": "function",
}
`);
});
describe('getRequestAggs', () => {
describe('initial aggregation creation', () => {
let aggConfigs: IAggConfigs;

View file

@ -21,6 +21,7 @@ import { i18n } from '@kbn/i18n';
import { BucketAggType, IBucketAggConfig } from './bucket_agg_type';
import { KBN_FIELD_TYPES } from '../../../../common';
import { BUCKET_TYPES } from './bucket_agg_types';
import { aggGeoHashFnName } from './geo_hash_fn';
import { GeoBoundingBox } from './lib/geo_point';
import { BaseAggParams } from '../types';
@ -47,6 +48,7 @@ export interface AggParamsGeoHash extends BaseAggParams {
export const getGeoHashBucketAgg = () =>
new BucketAggType<IBucketAggConfig>({
name: BUCKET_TYPES.GEOHASH_GRID,
expressionName: aggGeoHashFnName,
title: geohashGridTitle,
makeLabel: () => geohashGridTitle,
params: [

View file

@ -23,17 +23,22 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, BUCKET_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggGeoHash';
export const aggGeoHashFnName = 'aggGeoHash';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.GEOHASH_GRID>;
type Arguments = Assign<AggArgs, { boundingBox?: string }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggGeoHashFnName,
Input,
Arguments,
Output
>;
export const aggGeoHash = (): FunctionDefinition => ({
name: fnName,
name: aggGeoHashFnName,
help: i18n.translate('data.search.aggs.function.buckets.geoHash.help', {
defaultMessage: 'Generates a serialized agg config for a Geo Hash agg',
}),

View file

@ -22,6 +22,7 @@ import { noop } from 'lodash';
import { BucketAggType, IBucketAggConfig } from './bucket_agg_type';
import { BUCKET_TYPES } from './bucket_agg_types';
import { aggGeoTileFnName } from './geo_tile_fn';
import { KBN_FIELD_TYPES } from '../../../../common';
import { METRIC_TYPES } from '../metrics/metric_agg_types';
import { BaseAggParams } from '../types';
@ -39,6 +40,7 @@ export interface AggParamsGeoTile extends BaseAggParams {
export const getGeoTitleBucketAgg = () =>
new BucketAggType({
name: BUCKET_TYPES.GEOTILE_GRID,
expressionName: aggGeoTileFnName,
title: geotileGridTitle,
params: [
{

View file

@ -22,16 +22,21 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, BUCKET_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggGeoTile';
export const aggGeoTileFnName = 'aggGeoTile';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.GEOTILE_GRID>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggGeoTileFnName,
Input,
AggArgs,
Output
>;
export const aggGeoTile = (): FunctionDefinition => ({
name: fnName,
name: aggGeoTileFnName,
help: i18n.translate('data.search.aggs.function.buckets.geoTile.help', {
defaultMessage: 'Generates a serialized agg config for a Geo Tile agg',
}),

View file

@ -72,6 +72,50 @@ describe('Histogram Agg', () => {
return aggConfigs.aggs[0].toDsl()[BUCKET_TYPES.HISTOGRAM];
};
test('produces the expected expression ast', () => {
const aggConfigs = getAggConfigs({
intervalBase: 100,
field: {
name: 'field',
},
});
expect(aggConfigs.aggs[0].toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"enabled": Array [
true,
],
"extended_bounds": Array [
"{\\"min\\":\\"\\",\\"max\\":\\"\\"}",
],
"field": Array [
"field",
],
"has_extended_bounds": Array [
false,
],
"id": Array [
"test",
],
"interval": Array [
"auto",
],
"intervalBase": Array [
100,
],
"min_doc_count": Array [
false,
],
"schema": Array [
"segment",
],
},
"function": "aggHistogram",
"type": "function",
}
`);
});
describe('ordered', () => {
let histogramType: BucketAggType<IBucketHistogramAggConfig>;

View file

@ -27,6 +27,7 @@ import { BaseAggParams } from '../types';
import { BucketAggType, IBucketAggConfig } from './bucket_agg_type';
import { createFilterHistogram } from './create_filter/histogram';
import { BUCKET_TYPES } from './bucket_agg_types';
import { aggHistogramFnName } from './histogram_fn';
import { ExtendedBounds } from './lib/extended_bounds';
import { isAutoInterval, autoInterval } from './_interval_options';
import { calculateHistogramInterval } from './lib/histogram_calculate_interval';
@ -62,6 +63,7 @@ export const getHistogramBucketAgg = ({
}: HistogramBucketAggDependencies) =>
new BucketAggType<IBucketHistogramAggConfig>({
name: BUCKET_TYPES.HISTOGRAM,
expressionName: aggHistogramFnName,
title: i18n.translate('data.search.aggs.buckets.histogramTitle', {
defaultMessage: 'Histogram',
}),

View file

@ -23,7 +23,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, BUCKET_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggHistogram';
export const aggHistogramFnName = 'aggHistogram';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.HISTOGRAM>;
@ -31,10 +31,15 @@ type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.HISTOGRAM>;
type Arguments = Assign<AggArgs, { extended_bounds?: string }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggHistogramFnName,
Input,
Arguments,
Output
>;
export const aggHistogram = (): FunctionDefinition => ({
name: fnName,
name: aggHistogramFnName,
help: i18n.translate('data.search.aggs.function.buckets.histogram.help', {
defaultMessage: 'Generates a serialized agg config for a Histogram agg',
}),

View file

@ -24,6 +24,7 @@ import { BUCKET_TYPES } from './bucket_agg_types';
import { createFilterIpRange } from './create_filter/ip_range';
import { IpRangeKey, RangeIpRangeAggKey, CidrMaskIpRangeAggKey } from './lib/ip_range';
import { aggIpRangeFnName } from './ip_range_fn';
import { KBN_FIELD_TYPES } from '../../../../common';
import { BaseAggParams } from '../types';
@ -48,6 +49,7 @@ export interface AggParamsIpRange extends BaseAggParams {
export const getIpRangeBucketAgg = () =>
new BucketAggType({
name: BUCKET_TYPES.IP_RANGE,
expressionName: aggIpRangeFnName,
title: ipRangeTitle,
createFilter: createFilterIpRange,
getKey(bucket, key, agg): IpRangeKey {

View file

@ -23,7 +23,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, BUCKET_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggIpRange';
export const aggIpRangeFnName = 'aggIpRange';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.IP_RANGE>;
@ -31,10 +31,15 @@ type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.IP_RANGE>;
type Arguments = Assign<AggArgs, { ranges?: string; ipRangeType?: string }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggIpRangeFnName,
Input,
Arguments,
Output
>;
export const aggIpRange = (): FunctionDefinition => ({
name: fnName,
name: aggIpRangeFnName,
help: i18n.translate('data.search.aggs.function.buckets.ipRange.help', {
defaultMessage: 'Generates a serialized agg config for a Ip Range agg',
}),

View file

@ -66,6 +66,33 @@ describe('Range Agg', () => {
);
};
test('produces the expected expression ast', () => {
const aggConfigs = getAggConfigs();
expect(aggConfigs.aggs[0].toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"enabled": Array [
true,
],
"field": Array [
"bytes",
],
"id": Array [
"1",
],
"ranges": Array [
"[{\\"from\\":0,\\"to\\":1000},{\\"from\\":1000,\\"to\\":2000}]",
],
"schema": Array [
"segment",
],
},
"function": "aggRange",
"type": "function",
}
`);
});
describe('getSerializedFormat', () => {
test('generates a serialized field format in the expected shape', () => {
const aggConfigs = getAggConfigs();

View file

@ -24,6 +24,7 @@ import { AggTypesDependencies } from '../agg_types';
import { BaseAggParams } from '../types';
import { BucketAggType } from './bucket_agg_type';
import { aggRangeFnName } from './range_fn';
import { RangeKey } from './range_key';
import { createFilterRange } from './create_filter/range';
import { BUCKET_TYPES } from './bucket_agg_types';
@ -50,6 +51,7 @@ export const getRangeBucketAgg = ({ getFieldFormatsStart }: RangeBucketAggDepend
return new BucketAggType({
name: BUCKET_TYPES.RANGE,
expressionName: aggRangeFnName,
title: rangeTitle,
createFilter: createFilterRange(getFieldFormatsStart),
makeLabel(aggConfig) {

View file

@ -23,7 +23,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, BUCKET_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggRange';
export const aggRangeFnName = 'aggRange';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.RANGE>;
@ -31,10 +31,15 @@ type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.RANGE>;
type Arguments = Assign<AggArgs, { ranges?: string }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggRangeFnName,
Input,
Arguments,
Output
>;
export const aggRange = (): FunctionDefinition => ({
name: fnName,
name: aggRangeFnName,
help: i18n.translate('data.search.aggs.function.buckets.range.help', {
defaultMessage: 'Generates a serialized agg config for a Range agg',
}),

View file

@ -60,6 +60,27 @@ describe('Shard Delay Agg', () => {
);
};
test('produces the expected expression ast', () => {
const aggConfigs = getAggConfigs();
expect(aggConfigs.aggs[0].toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"delay": Array [
"5s",
],
"enabled": Array [
true,
],
"id": Array [
"1",
],
},
"function": "aggShardDelay",
"type": "function",
}
`);
});
describe('write', () => {
test('writes the delay as the value parameter', () => {
const aggConfigs = getAggConfigs();

View file

@ -64,6 +64,38 @@ describe('Significant Terms Agg', () => {
expect(params.exclude).toBe('400');
};
test('produces the expected expression ast', () => {
const aggConfigs = getAggConfigs({
size: 'SIZE',
field: {
name: 'FIELD',
},
});
expect(aggConfigs.aggs[0].toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"enabled": Array [
true,
],
"field": Array [
"FIELD",
],
"id": Array [
"test",
],
"schema": Array [
"segment",
],
"size": Array [
"SIZE",
],
},
"function": "aggSignificantTerms",
"type": "function",
}
`);
});
test('should generate correct label', () => {
const aggConfigs = getAggConfigs({
size: 'SIZE',

View file

@ -22,6 +22,7 @@ import { BucketAggType } from './bucket_agg_type';
import { createFilterTerms } from './create_filter/terms';
import { isStringType, migrateIncludeExcludeFormat } from './migrate_include_exclude_format';
import { BUCKET_TYPES } from './bucket_agg_types';
import { aggSignificantTermsFnName } from './significant_terms_fn';
import { KBN_FIELD_TYPES } from '../../../../common';
import { BaseAggParams } from '../types';
@ -39,6 +40,7 @@ export interface AggParamsSignificantTerms extends BaseAggParams {
export const getSignificantTermsBucketAgg = () =>
new BucketAggType({
name: BUCKET_TYPES.SIGNIFICANT_TERMS,
expressionName: aggSignificantTermsFnName,
title: significantTermsTitle,
makeLabel(aggConfig) {
return i18n.translate('data.search.aggs.buckets.significantTermsLabel', {

View file

@ -22,7 +22,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, BUCKET_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggSignificantTerms';
export const aggSignificantTermsFnName = 'aggSignificantTerms';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.SIGNIFICANT_TERMS>;
@ -30,10 +30,15 @@ type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.SIGNIFICANT_TERMS>;
type Arguments = AggArgs;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggSignificantTermsFnName,
Input,
Arguments,
Output
>;
export const aggSignificantTerms = (): FunctionDefinition => ({
name: fnName,
name: aggSignificantTermsFnName,
help: i18n.translate('data.search.aggs.function.buckets.significantTerms.help', {
defaultMessage: 'Generates a serialized agg config for a Significant Terms agg',
}),

View file

@ -52,6 +52,80 @@ describe('Terms Agg', () => {
);
};
test('produces the expected expression ast', () => {
const aggConfigs = getAggConfigs({
include: {
pattern: '404',
},
exclude: {
pattern: '400',
},
field: {
name: 'field',
},
orderAgg: {
type: 'count',
},
});
expect(aggConfigs.aggs[0].toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"enabled": Array [
true,
],
"field": Array [
"field",
],
"id": Array [
"test",
],
"missingBucket": Array [
false,
],
"missingBucketLabel": Array [
"Missing",
],
"order": Array [
"desc",
],
"orderAgg": Array [
Object {
"chain": Array [
Object {
"arguments": Object {
"enabled": Array [
true,
],
"id": Array [
"test-orderAgg",
],
"schema": Array [
"orderAgg",
],
},
"function": "aggCount",
"type": "function",
},
],
"type": "expression",
},
],
"otherBucket": Array [
false,
],
"otherBucketLabel": Array [
"Other",
],
"size": Array [
5,
],
},
"function": "aggTerms",
"type": "function",
}
`);
});
test('converts object to string type', () => {
const aggConfigs = getAggConfigs({
include: {

View file

@ -28,6 +28,7 @@ import {
isStringOrNumberType,
migrateIncludeExcludeFormat,
} from './migrate_include_exclude_format';
import { aggTermsFnName } from './terms_fn';
import { AggConfigSerialized, BaseAggParams } from '../types';
import { KBN_FIELD_TYPES } from '../../../../common';
@ -75,7 +76,7 @@ export interface AggParamsTerms extends BaseAggParams {
export const getTermsBucketAgg = () =>
new BucketAggType({
name: BUCKET_TYPES.TERMS,
expressionName: 'aggTerms',
expressionName: aggTermsFnName,
title: termsTitle,
makeLabel(agg) {
const params = agg.params;

View file

@ -23,7 +23,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, BUCKET_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggTerms';
export const aggTermsFnName = 'aggTerms';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.TERMS>;
@ -33,10 +33,15 @@ type AggArgs = AggExpressionFunctionArgs<typeof BUCKET_TYPES.TERMS>;
type Arguments = Assign<AggArgs, { orderAgg?: AggExpressionType }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggTermsFnName,
Input,
Arguments,
Output
>;
export const aggTerms = (): FunctionDefinition => ({
name: fnName,
name: aggTermsFnName,
help: i18n.translate('data.search.aggs.function.buckets.terms.help', {
defaultMessage: 'Generates a serialized agg config for a Terms agg',
}),

View file

@ -18,6 +18,7 @@
*/
import { i18n } from '@kbn/i18n';
import { aggAvgFnName } from './avg_fn';
import { MetricAggType } from './metric_agg_type';
import { METRIC_TYPES } from './metric_agg_types';
import { KBN_FIELD_TYPES } from '../../../../common';
@ -34,6 +35,7 @@ export interface AggParamsAvg extends BaseAggParams {
export const getAvgMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.AVG,
expressionName: aggAvgFnName,
title: averageTitle,
makeLabel: (aggConfig) => {
return i18n.translate('data.search.aggs.metrics.averageLabel', {

View file

@ -22,15 +22,15 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggAvg';
export const aggAvgFnName = 'aggAvg';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.AVG>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<typeof aggAvgFnName, Input, AggArgs, Output>;
export const aggAvg = (): FunctionDefinition => ({
name: fnName,
name: aggAvgFnName,
help: i18n.translate('data.search.aggs.function.metrics.avg.help', {
defaultMessage: 'Generates a serialized agg config for a Avg agg',
}),

View file

@ -19,6 +19,7 @@
import { i18n } from '@kbn/i18n';
import { get } from 'lodash';
import { aggBucketAvgFnName } from './bucket_avg_fn';
import { MetricAggType } from './metric_agg_type';
import { makeNestedLabel } from './lib/make_nested_label';
import { siblingPipelineAggHelper } from './lib/sibling_pipeline_agg_helper';
@ -43,6 +44,7 @@ export const getBucketAvgMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.AVG_BUCKET,
expressionName: aggBucketAvgFnName,
title: averageBucketTitle,
makeLabel: (agg) => makeNestedLabel(agg, overallAverageLabel),
subtype,

View file

@ -23,7 +23,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggBucketAvg';
export const aggBucketAvgFnName = 'aggBucketAvg';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.AVG_BUCKET>;
@ -32,10 +32,15 @@ type Arguments = Assign<
{ customBucket?: AggExpressionType; customMetric?: AggExpressionType }
>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggBucketAvgFnName,
Input,
Arguments,
Output
>;
export const aggBucketAvg = (): FunctionDefinition => ({
name: fnName,
name: aggBucketAvgFnName,
help: i18n.translate('data.search.aggs.function.metrics.bucket_avg.help', {
defaultMessage: 'Generates a serialized agg config for a Avg Bucket agg',
}),

View file

@ -18,6 +18,7 @@
*/
import { i18n } from '@kbn/i18n';
import { aggBucketMaxFnName } from './bucket_max_fn';
import { MetricAggType } from './metric_agg_type';
import { makeNestedLabel } from './lib/make_nested_label';
import { siblingPipelineAggHelper } from './lib/sibling_pipeline_agg_helper';
@ -42,6 +43,7 @@ export const getBucketMaxMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.MAX_BUCKET,
expressionName: aggBucketMaxFnName,
title: maxBucketTitle,
makeLabel: (agg) => makeNestedLabel(agg, overallMaxLabel),
subtype,

View file

@ -23,7 +23,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggBucketMax';
export const aggBucketMaxFnName = 'aggBucketMax';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.MAX_BUCKET>;
@ -32,10 +32,15 @@ type Arguments = Assign<
{ customBucket?: AggExpressionType; customMetric?: AggExpressionType }
>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggBucketMaxFnName,
Input,
Arguments,
Output
>;
export const aggBucketMax = (): FunctionDefinition => ({
name: fnName,
name: aggBucketMaxFnName,
help: i18n.translate('data.search.aggs.function.metrics.bucket_max.help', {
defaultMessage: 'Generates a serialized agg config for a Max Bucket agg',
}),

View file

@ -18,6 +18,7 @@
*/
import { i18n } from '@kbn/i18n';
import { aggBucketMinFnName } from './bucket_min_fn';
import { MetricAggType } from './metric_agg_type';
import { makeNestedLabel } from './lib/make_nested_label';
import { siblingPipelineAggHelper } from './lib/sibling_pipeline_agg_helper';
@ -42,6 +43,7 @@ export const getBucketMinMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.MIN_BUCKET,
expressionName: aggBucketMinFnName,
title: minBucketTitle,
makeLabel: (agg) => makeNestedLabel(agg, overallMinLabel),
subtype,

View file

@ -23,7 +23,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggBucketMin';
export const aggBucketMinFnName = 'aggBucketMin';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.MIN_BUCKET>;
@ -32,10 +32,15 @@ type Arguments = Assign<
{ customBucket?: AggExpressionType; customMetric?: AggExpressionType }
>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggBucketMinFnName,
Input,
Arguments,
Output
>;
export const aggBucketMin = (): FunctionDefinition => ({
name: fnName,
name: aggBucketMinFnName,
help: i18n.translate('data.search.aggs.function.metrics.bucket_min.help', {
defaultMessage: 'Generates a serialized agg config for a Min Bucket agg',
}),

View file

@ -18,6 +18,7 @@
*/
import { i18n } from '@kbn/i18n';
import { aggBucketSumFnName } from './bucket_sum_fn';
import { MetricAggType } from './metric_agg_type';
import { makeNestedLabel } from './lib/make_nested_label';
import { siblingPipelineAggHelper } from './lib/sibling_pipeline_agg_helper';
@ -42,6 +43,7 @@ export const getBucketSumMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.SUM_BUCKET,
expressionName: aggBucketSumFnName,
title: sumBucketTitle,
makeLabel: (agg) => makeNestedLabel(agg, overallSumLabel),
subtype,

View file

@ -23,7 +23,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggBucketSum';
export const aggBucketSumFnName = 'aggBucketSum';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.SUM_BUCKET>;
@ -32,10 +32,15 @@ type Arguments = Assign<
{ customBucket?: AggExpressionType; customMetric?: AggExpressionType }
>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggBucketSumFnName,
Input,
Arguments,
Output
>;
export const aggBucketSum = (): FunctionDefinition => ({
name: fnName,
name: aggBucketSumFnName,
help: i18n.translate('data.search.aggs.function.metrics.bucket_sum.help', {
defaultMessage: 'Generates a serialized agg config for a Sum Bucket agg',
}),

View file

@ -18,6 +18,7 @@
*/
import { i18n } from '@kbn/i18n';
import { aggCardinalityFnName } from './cardinality_fn';
import { MetricAggType, IMetricAggConfig } from './metric_agg_type';
import { METRIC_TYPES } from './metric_agg_types';
import { KBN_FIELD_TYPES } from '../../../../common';
@ -34,6 +35,7 @@ export interface AggParamsCardinality extends BaseAggParams {
export const getCardinalityMetricAgg = () =>
new MetricAggType({
name: METRIC_TYPES.CARDINALITY,
expressionName: aggCardinalityFnName,
title: uniqueCountTitle,
makeLabel(aggConfig: IMetricAggConfig) {
return i18n.translate('data.search.aggs.metrics.uniqueCountLabel', {

View file

@ -22,15 +22,20 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggCardinality';
export const aggCardinalityFnName = 'aggCardinality';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.CARDINALITY>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggCardinalityFnName,
Input,
AggArgs,
Output
>;
export const aggCardinality = (): FunctionDefinition => ({
name: fnName,
name: aggCardinalityFnName,
help: i18n.translate('data.search.aggs.function.metrics.cardinality.help', {
defaultMessage: 'Generates a serialized agg config for a Cardinality agg',
}),

View file

@ -18,12 +18,14 @@
*/
import { i18n } from '@kbn/i18n';
import { aggCountFnName } from './count_fn';
import { MetricAggType } from './metric_agg_type';
import { METRIC_TYPES } from './metric_agg_types';
export const getCountMetricAgg = () =>
new MetricAggType({
name: METRIC_TYPES.COUNT,
expressionName: aggCountFnName,
title: i18n.translate('data.search.aggs.metrics.countTitle', {
defaultMessage: 'Count',
}),

View file

@ -21,15 +21,20 @@ import { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
const fnName = 'aggCount';
export const aggCountFnName = 'aggCount';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.COUNT>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggCountFnName,
Input,
AggArgs,
Output
>;
export const aggCount = (): FunctionDefinition => ({
name: fnName,
name: aggCountFnName,
help: i18n.translate('data.search.aggs.function.metrics.count.help', {
defaultMessage: 'Generates a serialized agg config for a Count agg',
}),

View file

@ -18,6 +18,7 @@
*/
import { i18n } from '@kbn/i18n';
import { aggCumulativeSumFnName } from './cumulative_sum_fn';
import { MetricAggType } from './metric_agg_type';
import { parentPipelineAggHelper } from './lib/parent_pipeline_agg_helper';
import { makeNestedLabel } from './lib/make_nested_label';
@ -43,6 +44,7 @@ export const getCumulativeSumMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.CUMULATIVE_SUM,
expressionName: aggCumulativeSumFnName,
title: cumulativeSumTitle,
makeLabel: (agg) => makeNestedLabel(agg, cumulativeSumLabel),
subtype,

View file

@ -23,16 +23,21 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggCumulativeSum';
export const aggCumulativeSumFnName = 'aggCumulativeSum';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.CUMULATIVE_SUM>;
type Arguments = Assign<AggArgs, { customMetric?: AggExpressionType }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggCumulativeSumFnName,
Input,
Arguments,
Output
>;
export const aggCumulativeSum = (): FunctionDefinition => ({
name: fnName,
name: aggCumulativeSumFnName,
help: i18n.translate('data.search.aggs.function.metrics.cumulative_sum.help', {
defaultMessage: 'Generates a serialized agg config for a Cumulative Sum agg',
}),

View file

@ -18,6 +18,7 @@
*/
import { i18n } from '@kbn/i18n';
import { aggDerivativeFnName } from './derivative_fn';
import { MetricAggType } from './metric_agg_type';
import { parentPipelineAggHelper } from './lib/parent_pipeline_agg_helper';
import { makeNestedLabel } from './lib/make_nested_label';
@ -43,6 +44,7 @@ export const getDerivativeMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.DERIVATIVE,
expressionName: aggDerivativeFnName,
title: derivativeTitle,
makeLabel(agg) {
return makeNestedLabel(agg, derivativeLabel);

View file

@ -23,16 +23,21 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggDerivative';
export const aggDerivativeFnName = 'aggDerivative';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.DERIVATIVE>;
type Arguments = Assign<AggArgs, { customMetric?: AggExpressionType }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggDerivativeFnName,
Input,
Arguments,
Output
>;
export const aggDerivative = (): FunctionDefinition => ({
name: fnName,
name: aggDerivativeFnName,
help: i18n.translate('data.search.aggs.function.metrics.derivative.help', {
defaultMessage: 'Generates a serialized agg config for a Derivative agg',
}),

View file

@ -18,6 +18,7 @@
*/
import { i18n } from '@kbn/i18n';
import { aggGeoBoundsFnName } from './geo_bounds_fn';
import { MetricAggType } from './metric_agg_type';
import { METRIC_TYPES } from './metric_agg_types';
import { KBN_FIELD_TYPES } from '../../../../common';
@ -38,6 +39,7 @@ const geoBoundsLabel = i18n.translate('data.search.aggs.metrics.geoBoundsLabel',
export const getGeoBoundsMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.GEO_BOUNDS,
expressionName: aggGeoBoundsFnName,
title: geoBoundsTitle,
makeLabel: () => geoBoundsLabel,
params: [

View file

@ -22,15 +22,20 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggGeoBounds';
export const aggGeoBoundsFnName = 'aggGeoBounds';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.GEO_BOUNDS>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggGeoBoundsFnName,
Input,
AggArgs,
Output
>;
export const aggGeoBounds = (): FunctionDefinition => ({
name: fnName,
name: aggGeoBoundsFnName,
help: i18n.translate('data.search.aggs.function.metrics.geo_bounds.help', {
defaultMessage: 'Generates a serialized agg config for a Geo Bounds agg',
}),

View file

@ -18,6 +18,7 @@
*/
import { i18n } from '@kbn/i18n';
import { aggGeoCentroidFnName } from './geo_centroid_fn';
import { MetricAggType } from './metric_agg_type';
import { METRIC_TYPES } from './metric_agg_types';
import { KBN_FIELD_TYPES } from '../../../../common';
@ -38,6 +39,7 @@ const geoCentroidLabel = i18n.translate('data.search.aggs.metrics.geoCentroidLab
export const getGeoCentroidMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.GEO_CENTROID,
expressionName: aggGeoCentroidFnName,
title: geoCentroidTitle,
makeLabel: () => geoCentroidLabel,
params: [

View file

@ -22,15 +22,20 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggGeoCentroid';
export const aggGeoCentroidFnName = 'aggGeoCentroid';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.GEO_CENTROID>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggGeoCentroidFnName,
Input,
AggArgs,
Output
>;
export const aggGeoCentroid = (): FunctionDefinition => ({
name: fnName,
name: aggGeoCentroidFnName,
help: i18n.translate('data.search.aggs.function.metrics.geo_centroid.help', {
defaultMessage: 'Generates a serialized agg config for a Geo Centroid agg',
}),

View file

@ -18,6 +18,7 @@
*/
import { i18n } from '@kbn/i18n';
import { aggMaxFnName } from './max_fn';
import { MetricAggType } from './metric_agg_type';
import { METRIC_TYPES } from './metric_agg_types';
import { KBN_FIELD_TYPES } from '../../../../common';
@ -34,6 +35,7 @@ export interface AggParamsMax extends BaseAggParams {
export const getMaxMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.MAX,
expressionName: aggMaxFnName,
title: maxTitle,
makeLabel(aggConfig) {
return i18n.translate('data.search.aggs.metrics.maxLabel', {

View file

@ -22,15 +22,15 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggMax';
export const aggMaxFnName = 'aggMax';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.MAX>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<typeof aggMaxFnName, Input, AggArgs, Output>;
export const aggMax = (): FunctionDefinition => ({
name: fnName,
name: aggMaxFnName,
help: i18n.translate('data.search.aggs.function.metrics.max.help', {
defaultMessage: 'Generates a serialized agg config for a Max agg',
}),

View file

@ -82,4 +82,28 @@ describe('AggTypeMetricMedianProvider class', () => {
})
).toEqual(10);
});
it('produces the expected expression ast', () => {
const agg = aggConfigs.getResponseAggs()[0];
expect(agg.toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"enabled": Array [
true,
],
"field": Array [
"bytes",
],
"id": Array [
"median",
],
"schema": Array [
"metric",
],
},
"function": "aggMedian",
"type": "function",
}
`);
});
});

View file

@ -18,6 +18,7 @@
*/
import { i18n } from '@kbn/i18n';
import { aggMedianFnName } from './median_fn';
import { MetricAggType } from './metric_agg_type';
import { METRIC_TYPES } from './metric_agg_types';
import { KBN_FIELD_TYPES } from '../../../../common';
@ -34,6 +35,7 @@ export interface AggParamsMedian extends BaseAggParams {
export const getMedianMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.MEDIAN,
expressionName: aggMedianFnName,
dslName: 'percentiles',
title: medianTitle,
makeLabel(aggConfig) {

View file

@ -22,15 +22,20 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggMedian';
export const aggMedianFnName = 'aggMedian';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.MEDIAN>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggMedianFnName,
Input,
AggArgs,
Output
>;
export const aggMedian = (): FunctionDefinition => ({
name: fnName,
name: aggMedianFnName,
help: i18n.translate('data.search.aggs.function.metrics.median.help', {
defaultMessage: 'Generates a serialized agg config for a Median agg',
}),

View file

@ -20,6 +20,7 @@
import { i18n } from '@kbn/i18n';
import { MetricAggType } from './metric_agg_type';
import { METRIC_TYPES } from './metric_agg_types';
import { aggMinFnName } from './min_fn';
import { KBN_FIELD_TYPES } from '../../../../common';
import { BaseAggParams } from '../types';
@ -34,6 +35,7 @@ export interface AggParamsMin extends BaseAggParams {
export const getMinMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.MIN,
expressionName: aggMinFnName,
title: minTitle,
makeLabel(aggConfig) {
return i18n.translate('data.search.aggs.metrics.minLabel', {

View file

@ -22,15 +22,15 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggMin';
export const aggMinFnName = 'aggMin';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.MIN>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<typeof aggMinFnName, Input, AggArgs, Output>;
export const aggMin = (): FunctionDefinition => ({
name: fnName,
name: aggMinFnName,
help: i18n.translate('data.search.aggs.function.metrics.min.help', {
defaultMessage: 'Generates a serialized agg config for a Min agg',
}),

View file

@ -19,6 +19,7 @@
import { i18n } from '@kbn/i18n';
import { MetricAggType } from './metric_agg_type';
import { aggMovingAvgFnName } from './moving_avg_fn';
import { parentPipelineAggHelper } from './lib/parent_pipeline_agg_helper';
import { makeNestedLabel } from './lib/make_nested_label';
import { METRIC_TYPES } from './metric_agg_types';
@ -45,6 +46,7 @@ export const getMovingAvgMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.MOVING_FN,
expressionName: aggMovingAvgFnName,
dslName: 'moving_fn',
title: movingAvgTitle,
makeLabel: (agg) => makeNestedLabel(agg, movingAvgLabel),

View file

@ -23,16 +23,21 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggMovingAvg';
export const aggMovingAvgFnName = 'aggMovingAvg';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.MOVING_FN>;
type Arguments = Assign<AggArgs, { customMetric?: AggExpressionType }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggMovingAvgFnName,
Input,
Arguments,
Output
>;
export const aggMovingAvg = (): FunctionDefinition => ({
name: fnName,
name: aggMovingAvgFnName,
help: i18n.translate('data.search.aggs.function.metrics.moving_avg.help', {
defaultMessage: 'Generates a serialized agg config for a Moving Average agg',
}),

View file

@ -63,7 +63,7 @@ describe('AggTypesMetricsPercentileRanksProvider class', function () {
);
});
it('uses the custom label if it is set', function () {
it('uses the custom label if it is set', () => {
const responseAggs: any = getPercentileRanksMetricAgg(aggTypesDependencies).getResponseAggs(
aggConfigs.aggs[0] as IPercentileRanksAggConfig
);
@ -74,4 +74,62 @@ describe('AggTypesMetricsPercentileRanksProvider class', function () {
expect(percentileRankLabelFor5kBytes).toBe('Percentile rank 5000 of "my custom field label"');
expect(percentileRankLabelFor10kBytes).toBe('Percentile rank 10000 of "my custom field label"');
});
it('produces the expected expression ast', () => {
const responseAggs: any = getPercentileRanksMetricAgg(aggTypesDependencies).getResponseAggs(
aggConfigs.aggs[0] as IPercentileRanksAggConfig
);
expect(responseAggs[0].toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"customLabel": Array [
"my custom field label",
],
"enabled": Array [
true,
],
"field": Array [
"bytes",
],
"id": Array [
"percentile_ranks.5000",
],
"schema": Array [
"metric",
],
"values": Array [
"[5000,10000]",
],
},
"function": "aggPercentileRanks",
"type": "function",
}
`);
expect(responseAggs[1].toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"customLabel": Array [
"my custom field label",
],
"enabled": Array [
true,
],
"field": Array [
"bytes",
],
"id": Array [
"percentile_ranks.10000",
],
"schema": Array [
"metric",
],
"values": Array [
"[5000,10000]",
],
},
"function": "aggPercentileRanks",
"type": "function",
}
`);
});
});

View file

@ -25,6 +25,7 @@ import { BaseAggParams } from '../types';
import { MetricAggType } from './metric_agg_type';
import { getResponseAggConfigClass, IResponseAggConfig } from './lib/get_response_agg_config_class';
import { aggPercentileRanksFnName } from './percentile_ranks_fn';
import { getPercentileValue } from './percentiles_get_value';
import { METRIC_TYPES } from './metric_agg_types';
@ -64,6 +65,7 @@ export const getPercentileRanksMetricAgg = ({
}: PercentileRanksMetricAggDependencies) => {
return new MetricAggType<IPercentileRanksAggConfig>({
name: METRIC_TYPES.PERCENTILE_RANKS,
expressionName: aggPercentileRanksFnName,
title: i18n.translate('data.search.aggs.metrics.percentileRanksTitle', {
defaultMessage: 'Percentile Ranks',
}),

View file

@ -22,15 +22,20 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggPercentileRanks';
export const aggPercentileRanksFnName = 'aggPercentileRanks';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.PERCENTILE_RANKS>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggPercentileRanksFnName,
Input,
AggArgs,
Output
>;
export const aggPercentileRanks = (): FunctionDefinition => ({
name: fnName,
name: aggPercentileRanksFnName,
help: i18n.translate('data.search.aggs.function.metrics.percentile_ranks.help', {
defaultMessage: 'Generates a serialized agg config for a Percentile Ranks agg',
}),

View file

@ -66,4 +66,36 @@ describe('AggTypesMetricsPercentilesProvider class', () => {
expect(ninetyFifthPercentileLabel).toBe('95th percentile of prince');
});
it('produces the expected expression ast', () => {
const responseAggs: any = getPercentilesMetricAgg().getResponseAggs(
aggConfigs.aggs[0] as IPercentileAggConfig
);
expect(responseAggs[0].toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"customLabel": Array [
"prince",
],
"enabled": Array [
true,
],
"field": Array [
"bytes",
],
"id": Array [
"percentiles.95",
],
"percents": Array [
"[95]",
],
"schema": Array [
"metric",
],
},
"function": "aggPercentiles",
"type": "function",
}
`);
});
});

View file

@ -22,6 +22,7 @@ import { MetricAggType } from './metric_agg_type';
import { METRIC_TYPES } from './metric_agg_types';
import { KBN_FIELD_TYPES } from '../../../../common';
import { getResponseAggConfigClass, IResponseAggConfig } from './lib/get_response_agg_config_class';
import { aggPercentilesFnName } from './percentiles_fn';
import { getPercentileValue } from './percentiles_get_value';
import { ordinalSuffix } from './lib/ordinal_suffix';
import { BaseAggParams } from '../types';
@ -48,6 +49,7 @@ const valueProps = {
export const getPercentilesMetricAgg = () => {
return new MetricAggType<IPercentileAggConfig>({
name: METRIC_TYPES.PERCENTILES,
expressionName: aggPercentilesFnName,
title: i18n.translate('data.search.aggs.metrics.percentilesTitle', {
defaultMessage: 'Percentiles',
}),

View file

@ -22,15 +22,20 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggPercentiles';
export const aggPercentilesFnName = 'aggPercentiles';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.PERCENTILES>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggPercentilesFnName,
Input,
AggArgs,
Output
>;
export const aggPercentiles = (): FunctionDefinition => ({
name: fnName,
name: aggPercentilesFnName,
help: i18n.translate('data.search.aggs.function.metrics.percentiles.help', {
defaultMessage: 'Generates a serialized agg config for a Percentiles agg',
}),

View file

@ -19,6 +19,7 @@
import { i18n } from '@kbn/i18n';
import { MetricAggType } from './metric_agg_type';
import { aggSerialDiffFnName } from './serial_diff_fn';
import { parentPipelineAggHelper } from './lib/parent_pipeline_agg_helper';
import { makeNestedLabel } from './lib/make_nested_label';
import { METRIC_TYPES } from './metric_agg_types';
@ -43,6 +44,7 @@ export const getSerialDiffMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.SERIAL_DIFF,
expressionName: aggSerialDiffFnName,
title: serialDiffTitle,
makeLabel: (agg) => makeNestedLabel(agg, serialDiffLabel),
subtype,

View file

@ -23,16 +23,21 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggSerialDiff';
export const aggSerialDiffFnName = 'aggSerialDiff';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.SERIAL_DIFF>;
type Arguments = Assign<AggArgs, { customMetric?: AggExpressionType }>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggSerialDiffFnName,
Input,
Arguments,
Output
>;
export const aggSerialDiff = (): FunctionDefinition => ({
name: fnName,
name: aggSerialDiffFnName,
help: i18n.translate('data.search.aggs.function.metrics.serial_diff.help', {
defaultMessage: 'Generates a serialized agg config for a Serial Differencing agg',
}),

View file

@ -82,4 +82,29 @@ describe('AggTypeMetricStandardDeviationProvider class', () => {
expect(lowerStdDevLabel).toBe('Lower Standard Deviation of memory');
expect(upperStdDevLabel).toBe('Upper Standard Deviation of memory');
});
it('produces the expected expression ast', () => {
const aggConfigs = getAggConfigs();
const responseAggs: any = getStdDeviationMetricAgg().getResponseAggs(
aggConfigs.aggs[0] as IStdDevAggConfig
);
expect(responseAggs[0].toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"enabled": Array [
true,
],
"id": Array [
"std_dev.std_lower",
],
"schema": Array [
"metric",
],
},
"function": "aggStdDeviation",
"type": "function",
}
`);
});
});

View file

@ -20,6 +20,7 @@
import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
import { MetricAggType } from './metric_agg_type';
import { aggStdDeviationFnName } from './std_deviation_fn';
import { METRIC_TYPES } from './metric_agg_types';
import { getResponseAggConfigClass, IResponseAggConfig } from './lib/get_response_agg_config_class';
import { KBN_FIELD_TYPES } from '../../../../common';
@ -83,6 +84,7 @@ const responseAggConfigProps = {
export const getStdDeviationMetricAgg = () => {
return new MetricAggType<IStdDevAggConfig>({
name: METRIC_TYPES.STD_DEV,
expressionName: aggStdDeviationFnName,
dslName: 'extended_stats',
title: i18n.translate('data.search.aggs.metrics.standardDeviationTitle', {
defaultMessage: 'Standard Deviation',

View file

@ -22,15 +22,20 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggStdDeviation';
export const aggStdDeviationFnName = 'aggStdDeviation';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.STD_DEV>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggStdDeviationFnName,
Input,
AggArgs,
Output
>;
export const aggStdDeviation = (): FunctionDefinition => ({
name: fnName,
name: aggStdDeviationFnName,
help: i18n.translate('data.search.aggs.function.metrics.std_deviation.help', {
defaultMessage: 'Generates a serialized agg config for a Standard Deviation agg',
}),

View file

@ -19,6 +19,7 @@
import { i18n } from '@kbn/i18n';
import { MetricAggType } from './metric_agg_type';
import { aggSumFnName } from './sum_fn';
import { METRIC_TYPES } from './metric_agg_types';
import { KBN_FIELD_TYPES } from '../../../../common';
import { BaseAggParams } from '../types';
@ -34,6 +35,7 @@ export interface AggParamsSum extends BaseAggParams {
export const getSumMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.SUM,
expressionName: aggSumFnName,
title: sumTitle,
makeLabel(aggConfig) {
return i18n.translate('data.search.aggs.metrics.sumLabel', {

View file

@ -22,15 +22,15 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggSum';
export const aggSumFnName = 'aggSum';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.SUM>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<typeof aggSumFnName, Input, AggArgs, Output>;
export const aggSum = (): FunctionDefinition => ({
name: fnName,
name: aggSumFnName,
help: i18n.translate('data.search.aggs.function.metrics.sum.help', {
defaultMessage: 'Generates a serialized agg config for a Sum agg',
}),

View file

@ -102,6 +102,42 @@ describe('Top hit metric', () => {
expect(getTopHitMetricAgg().makeLabel(aggConfig)).toEqual('First bytes');
});
it('produces the expected expression ast', () => {
init({ fieldName: 'machine.os' });
expect(aggConfig.toExpressionAst()).toMatchInlineSnapshot(`
Object {
"arguments": Object {
"aggregate": Array [
"concat",
],
"enabled": Array [
true,
],
"field": Array [
"machine.os",
],
"id": Array [
"1",
],
"schema": Array [
"metric",
],
"size": Array [
1,
],
"sortField": Array [
"machine.os",
],
"sortOrder": Array [
"desc",
],
},
"function": "aggTopHit",
"type": "function",
}
`);
});
it('should request the _source field', () => {
init({ field: '_source' });
expect(aggDsl.top_hits._source).toBeTruthy();

View file

@ -19,6 +19,7 @@
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { aggTopHitFnName } from './top_hit_fn';
import { IMetricAggConfig, MetricAggType } from './metric_agg_type';
import { METRIC_TYPES } from './metric_agg_types';
import { KBN_FIELD_TYPES } from '../../../../common';
@ -41,6 +42,7 @@ const isNumericFieldSelected = (agg: IMetricAggConfig) => {
export const getTopHitMetricAgg = () => {
return new MetricAggType({
name: METRIC_TYPES.TOP_HITS,
expressionName: aggTopHitFnName,
title: i18n.translate('data.search.aggs.metrics.topHitTitle', {
defaultMessage: 'Top Hit',
}),

View file

@ -22,15 +22,20 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
const fnName = 'aggTopHit';
export const aggTopHitFnName = 'aggTopHit';
type Input = any;
type AggArgs = AggExpressionFunctionArgs<typeof METRIC_TYPES.TOP_HITS>;
type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, AggArgs, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggTopHitFnName,
Input,
AggArgs,
Output
>;
export const aggTopHit = (): FunctionDefinition => ({
name: fnName,
name: aggTopHitFnName,
help: i18n.translate('data.search.aggs.function.metrics.top_hit.help', {
defaultMessage: 'Generates a serialized agg config for a Top Hit agg',
}),

View file

@ -23,9 +23,10 @@ import {
TabularData,
TabularDataValue,
} from '../../../../../../plugins/inspector/common';
import { Filter, TabbedTable } from '../../../../common';
import { FormatFactory } from '../../../../common/field_formats/utils';
import { createFilter } from '../create_filter';
import { Filter } from '../../../es_query';
import { FormatFactory } from '../../../field_formats/utils';
import { TabbedTable } from '../../tabify';
import { createFilter } from './create_filter';
/**
* Type borrowed from the client-side FilterManager['addFilters'].

View file

@ -17,15 +17,11 @@
* under the License.
*/
import {
AggConfigs,
IAggConfig,
TabbedTable,
isRangeFilter,
BytesFormat,
FieldFormatsGetConfigFn,
} from '../../../common';
import { mockAggTypesRegistry } from '../../../common/search/aggs/test_helpers';
import { isRangeFilter } from '../../../es_query/filters';
import { BytesFormat, FieldFormatsGetConfigFn } from '../../../field_formats';
import { AggConfigs, IAggConfig } from '../../aggs';
import { mockAggTypesRegistry } from '../../aggs/test_helpers';
import { TabbedTable } from '../../tabify';
import { createFilter } from './create_filter';

View file

@ -17,7 +17,9 @@
* under the License.
*/
import { Filter, IAggConfig, TabbedTable } from '../../../common';
import { Filter } from '../../../es_query';
import { IAggConfig } from '../../aggs';
import { TabbedTable } from '../../tabify';
const getOtherBucketFilterTerms = (table: TabbedTable, columnIndex: number, rowIndex: number) => {
if (rowIndex === -1) {

View file

@ -0,0 +1,154 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { i18n } from '@kbn/i18n';
import {
Datatable,
DatatableColumn,
ExpressionFunctionDefinition,
} from 'src/plugins/expressions/common';
import { FormatFactory } from '../../../field_formats/utils';
import { IndexPatternsContract } from '../../../index_patterns/index_patterns';
import { calculateBounds } from '../../../query';
import { AggsStart } from '../../aggs';
import { ISearchStartSearchSource } from '../../search_source';
import { KibanaContext } from '../kibana_context_type';
import { AddFilters } from './build_tabular_inspector_data';
import { handleRequest, RequestHandlerParams } from './request_handler';
const name = 'esaggs';
type Input = KibanaContext | null;
type Output = Promise<Datatable>;
interface Arguments {
index: string;
metricsAtAllLevels: boolean;
partialRows: boolean;
includeFormatHints: boolean;
aggConfigs: string;
timeFields?: string[];
}
export type EsaggsExpressionFunctionDefinition = ExpressionFunctionDefinition<
'esaggs',
Input,
Arguments,
Output
>;
/** @internal */
export interface EsaggsStartDependencies {
addFilters?: AddFilters;
aggs: AggsStart;
deserializeFieldFormat: FormatFactory;
indexPatterns: IndexPatternsContract;
searchSource: ISearchStartSearchSource;
}
/** @internal */
export const getEsaggsMeta: () => Omit<EsaggsExpressionFunctionDefinition, 'fn'> = () => ({
name,
type: 'datatable',
inputTypes: ['kibana_context', 'null'],
help: i18n.translate('data.functions.esaggs.help', {
defaultMessage: 'Run AggConfig aggregation',
}),
args: {
index: {
types: ['string'],
help: '',
},
metricsAtAllLevels: {
types: ['boolean'],
default: false,
help: '',
},
partialRows: {
types: ['boolean'],
default: false,
help: '',
},
includeFormatHints: {
types: ['boolean'],
default: false,
help: '',
},
aggConfigs: {
types: ['string'],
default: '""',
help: '',
},
timeFields: {
types: ['string'],
help: '',
multi: true,
},
},
});
/** @internal */
export async function handleEsaggsRequest(
input: Input,
args: Arguments,
params: RequestHandlerParams
): Promise<Datatable> {
const resolvedTimeRange = input?.timeRange && calculateBounds(input.timeRange);
const response = await handleRequest(params);
const table: Datatable = {
type: 'datatable',
rows: response.rows,
columns: response.columns.map((column) => {
const cleanedColumn: DatatableColumn = {
id: column.id,
name: column.name,
meta: {
type: column.aggConfig.params.field?.type || 'number',
field: column.aggConfig.params.field?.name,
index: params.indexPattern?.title,
params: column.aggConfig.toSerializedFieldFormat(),
source: name,
sourceParams: {
indexPatternId: params.indexPattern?.id,
appliedTimeRange:
column.aggConfig.params.field?.name &&
input?.timeRange &&
args.timeFields &&
args.timeFields.includes(column.aggConfig.params.field?.name)
? {
from: resolvedTimeRange?.min?.toISOString(),
to: resolvedTimeRange?.max?.toISOString(),
}
: undefined,
...column.aggConfig.serialize(),
},
},
};
return cleanedColumn;
}),
};
return table;
}

View file

@ -40,7 +40,8 @@ import { FormatFactory } from '../../../../common/field_formats/utils';
import { AddFilters, buildTabularInspectorData } from './build_tabular_inspector_data';
interface RequestHandlerParams {
/** @internal */
export interface RequestHandlerParams {
abortSignal?: AbortSignal;
addFilters?: AddFilters;
aggs: IAggConfigs;

View file

@ -17,22 +17,27 @@
* under the License.
*/
import { indexPatternLoad } from './load_index_pattern';
jest.mock('../../services', () => ({
getIndexPatterns: () => ({
get: (id: string) => ({
toSpec: () => ({
title: 'value',
}),
}),
}),
}));
import { IndexPatternLoadStartDependencies } from '../../../common/index_patterns/expressions';
import { getFunctionDefinition } from './load_index_pattern';
describe('indexPattern expression function', () => {
let getStartDependencies: () => Promise<IndexPatternLoadStartDependencies>;
beforeEach(() => {
getStartDependencies = jest.fn().mockResolvedValue({
indexPatterns: {
get: (id: string) => ({
toSpec: () => ({
title: 'value',
}),
}),
},
});
});
test('returns serialized index pattern', async () => {
const indexPatternDefinition = indexPatternLoad();
const result = await indexPatternDefinition.fn(null, { id: '1' }, {} as any);
const indexPatternDefinition = getFunctionDefinition({ getStartDependencies });
const result = await indexPatternDefinition().fn(null, { id: '1' }, {} as any);
expect(result.type).toEqual('index_pattern');
expect(result.value.title).toEqual('value');
});

Some files were not shown because too many files have changed in this diff Show more