Skip to content

Commit

Permalink
[data.search][data.indexPatterns] Expose esaggs + indexPatternLoad on…
Browse files Browse the repository at this point in the history
… the server. (elastic#84590)
  • Loading branch information
lukeelmers committed Dec 3, 2020
1 parent 896187e commit 766e692
Show file tree
Hide file tree
Showing 122 changed files with 1,652 additions and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) | \* |
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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> | |

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +34,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) | | |
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
```
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
```
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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))();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
@@ -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',
}),
},
},
});
11 changes: 11 additions & 0 deletions src/plugins/data/common/search/aggs/agg_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('AggType Class', () => {
test('assigns the config value to itself', () => {
const config: AggTypeConfig = {
name: 'name',
expressionName: 'aggName',
title: 'title',
};

Expand All @@ -48,6 +49,7 @@ describe('AggType Class', () => {
const aggConfig = {} as IAggConfig;
const config: AggTypeConfig = {
name: 'name',
expressionName: 'aggName',
title: 'title',
makeLabel,
};
Expand All @@ -65,6 +67,7 @@ describe('AggType Class', () => {

const aggType = new AggType({
name: 'name',
expressionName: 'aggName',
title: 'title',
getResponseAggs: testConfig,
getRequestAggs: testConfig,
Expand All @@ -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);
Expand All @@ -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',
});

Expand All @@ -102,6 +107,7 @@ describe('AggType Class', () => {
test('disables json param', () => {
const aggType = new AggType({
name: 'name',
expressionName: 'aggName',
title: 'title',
json: false,
});
Expand All @@ -113,6 +119,7 @@ describe('AggType Class', () => {
test('can disable customLabel', () => {
const aggType = new AggType({
name: 'smart agg',
expressionName: 'aggSmart',
title: 'title',
customLabels: false,
});
Expand All @@ -127,6 +134,7 @@ describe('AggType Class', () => {

const aggType = new AggType({
name: 'bucketeer',
expressionName: 'aggBucketeer',
title: 'title',
params,
});
Expand All @@ -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(`
Expand All @@ -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 {}`);
Expand All @@ -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,
});
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/data/common/search/aggs/agg_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/common/search/aggs/buckets/date_histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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',
}),
Expand Down
Loading

0 comments on commit 766e692

Please sign in to comment.