Skip to content

Commit

Permalink
Use Search API in Vega (#68257)
Browse files Browse the repository at this point in the history
* Use Search API in Vega

* fix PR comments

* fix PR comments
  • Loading branch information
alexwizp authored Jun 9, 2020
1 parent ee5284e commit 5d8de7a
Show file tree
Hide file tree
Showing 21 changed files with 289 additions and 213 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!-- 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; [getSearchParamsFromRequest](./kibana-plugin-plugins-data-public.getsearchparamsfromrequest.md)

## getSearchParamsFromRequest() function

<b>Signature:</b>

```typescript
export declare function getSearchParamsFromRequest(searchRequest: SearchRequest, dependencies: {
injectedMetadata: CoreStart['injectedMetadata'];
uiSettings: IUiSettingsClient;
}): {
rest_total_hits_as_int: boolean;
ignore_unavailable: boolean;
ignore_throttled: boolean;
max_concurrent_shard_requests: any;
preference: any;
timeout: string | undefined;
index: any;
body: any;
};
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| searchRequest | <code>SearchRequest</code> | |
| dependencies | <code>{</code><br/><code> injectedMetadata: CoreStart['injectedMetadata'];</code><br/><code> uiSettings: IUiSettingsClient;</code><br/><code>}</code> | |

<b>Returns:</b>

`{
rest_total_hits_as_int: boolean;
ignore_unavailable: boolean;
ignore_throttled: boolean;
max_concurrent_shard_requests: any;
preference: any;
timeout: string | undefined;
index: any;
body: any;
}`

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
| [getEsPreference(uiSettings, sessionId)](./kibana-plugin-plugins-data-public.getespreference.md) | |
| [getQueryLog(uiSettings, storage, appName, language)](./kibana-plugin-plugins-data-public.getquerylog.md) | |
| [getSearchErrorType({ message })](./kibana-plugin-plugins-data-public.getsearcherrortype.md) | |
| [getSearchParamsFromRequest(searchRequest, dependencies)](./kibana-plugin-plugins-data-public.getsearchparamsfromrequest.md) | |
| [getTime(indexPattern, timeRange, options)](./kibana-plugin-plugins-data-public.gettime.md) | |
| [plugin(initializerContext)](./kibana-plugin-plugins-data-public.plugin.md) | |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import vegaMapImage256 from './vega_map_image_256.png';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { VegaParser } from '../../../../../../plugins/vis_type_vega/public/data_model/vega_parser';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { SearchCache } from '../../../../../../plugins/vis_type_vega/public/data_model/search_cache';
import { SearchAPI } from '../../../../../../plugins/vis_type_vega/public/data_model/search_api';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { createVegaTypeDefinition } from '../../../../../../plugins/vis_type_vega/public/vega_type';
Expand Down Expand Up @@ -205,7 +205,14 @@ describe('VegaVisualizations', () => {
try {
vegaVis = new VegaVisualization(domNode, vis);

const vegaParser = new VegaParser(vegaliteGraph, new SearchCache());
const vegaParser = new VegaParser(
vegaliteGraph,
new SearchAPI({
search: npStart.plugins.data.search,
uiSettings: npStart.core.uiSettings,
injectedMetadata: npStart.core.injectedMetadata,
})
);
await vegaParser.parseAsync();

await vegaVis.render(vegaParser, vis.params, { data: true });
Expand All @@ -227,7 +234,14 @@ describe('VegaVisualizations', () => {
let vegaVis;
try {
vegaVis = new VegaVisualization(domNode, vis);
const vegaParser = new VegaParser(vegaGraph, new SearchCache());
const vegaParser = new VegaParser(
vegaGraph,
new SearchAPI({
search: npStart.plugins.data.search,
uiSettings: npStart.core.uiSettings,
injectedMetadata: npStart.core.injectedMetadata,
})
);
await vegaParser.parseAsync();

await vegaVis.render(vegaParser, vis.params, { data: true });
Expand All @@ -243,7 +257,14 @@ describe('VegaVisualizations', () => {
let vegaVis;
try {
vegaVis = new VegaVisualization(domNode, vis);
const vegaParser = new VegaParser(vegaTooltipGraph, new SearchCache());
const vegaParser = new VegaParser(
vegaTooltipGraph,
new SearchAPI({
search: npStart.plugins.data.search,
uiSettings: npStart.core.uiSettings,
injectedMetadata: npStart.core.injectedMetadata,
})
);
await vegaParser.parseAsync();
await vegaVis.render(vegaParser, vis.params, { data: true });

Expand Down Expand Up @@ -285,7 +306,14 @@ describe('VegaVisualizations', () => {
let vegaVis;
try {
vegaVis = new VegaVisualization(domNode, vis);
const vegaParser = new VegaParser(vegaMapGraph, new SearchCache());
const vegaParser = new VegaParser(
vegaMapGraph,
new SearchAPI({
search: npStart.plugins.data.search,
uiSettings: npStart.core.uiSettings,
injectedMetadata: npStart.core.injectedMetadata,
})
);
await vegaParser.parseAsync();

domNode.style.width = '256px';
Expand Down Expand Up @@ -324,7 +352,11 @@ describe('VegaVisualizations', () => {
}
]
}`,
new SearchCache()
new SearchAPI({
search: npStart.plugins.data.search,
uiSettings: npStart.core.uiSettings,
injectedMetadata: npStart.core.injectedMetadata,
})
);
await vegaParser.parseAsync();

Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ export {
ISearchSource,
parseSearchSourceJSON,
injectSearchSourceReferences,
getSearchParamsFromRequest,
extractSearchSourceReferences,
SearchSourceFields,
EsQuerySortValue,
Expand Down
46 changes: 32 additions & 14 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { IconType } from '@elastic/eui';
import { InjectedIntl } from '@kbn/i18n/react';
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
import { IUiSettingsClient } from 'src/core/public';
import { IUiSettingsClient as IUiSettingsClient_3 } from 'kibana/public';
import { Location } from 'history';
import { LocationDescriptorObject } from 'history';
import { MaybePromise } from '@kbn/utility-types';
Expand Down Expand Up @@ -641,6 +642,23 @@ export function getQueryLog(uiSettings: IUiSettingsClient, storage: IStorageWrap
// @public (undocumented)
export function getSearchErrorType({ message }: Pick<SearchError, 'message'>): "UNSUPPORTED_QUERY" | undefined;

// Warning: (ae-missing-release-tag) "getSearchParamsFromRequest" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export function getSearchParamsFromRequest(searchRequest: SearchRequest, dependencies: {
injectedMetadata: CoreStart['injectedMetadata'];
uiSettings: IUiSettingsClient_3;
}): {
rest_total_hits_as_int: boolean;
ignore_unavailable: boolean;
ignore_throttled: boolean;
max_concurrent_shard_requests: any;
preference: any;
timeout: string | undefined;
index: any;
body: any;
};

// Warning: (ae-missing-release-tag) "getTime" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down Expand Up @@ -1851,20 +1869,20 @@ export const UI_SETTINGS: {
// src/plugins/data/public/index.ts:236:27 - (ae-forgotten-export) The symbol "getFromSavedObject" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:236:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:236:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:375:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:375:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:375:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:375:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:377:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:378:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:387:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:388:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:389:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:393:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:394:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:397:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:398:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:401:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:376:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:376:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:376:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:376:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:378:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:379:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:388:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:389:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:390:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:394:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:395:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:398:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:399:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:402:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:33:33 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:37:1 - (ae-forgotten-export) The symbol "QueryStateChange" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/types.ts:52:5 - (ae-forgotten-export) The symbol "createFiltersFromValueClickAction" needs to be exported by the entry point index.d.ts
Expand Down
18 changes: 17 additions & 1 deletion src/plugins/data/public/search/fetch/get_search_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
* under the License.
*/

import { IUiSettingsClient } from 'kibana/public';
import { IUiSettingsClient, CoreStart } from 'kibana/public';
import { UI_SETTINGS } from '../../../common';
import { SearchRequest } from './types';

const sessionId = Date.now();

Expand Down Expand Up @@ -53,3 +54,18 @@ export function getPreference(config: IUiSettingsClient) {
export function getTimeout(esShardTimeout: number) {
return esShardTimeout > 0 ? `${esShardTimeout}ms` : undefined;
}

export function getSearchParamsFromRequest(
searchRequest: SearchRequest,
dependencies: { injectedMetadata: CoreStart['injectedMetadata']; uiSettings: IUiSettingsClient }
) {
const { injectedMetadata, uiSettings } = dependencies;
const esShardTimeout = injectedMetadata.getInjectedVar('esShardTimeout') as number;
const searchParams = getSearchParams(uiSettings, esShardTimeout);

return {
index: searchRequest.index.title || searchRequest.index,
body: searchRequest.body,
...searchParams,
};
}
1 change: 1 addition & 0 deletions src/plugins/data/public/search/fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
export * from './types';
export {
getSearchParams,
getSearchParamsFromRequest,
getPreference,
getTimeout,
getIgnoreThrottled,
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export {
SearchRequest,
SearchResponse,
getSearchErrorType,
getSearchParamsFromRequest,
} from './fetch';

export {
Expand Down
15 changes: 7 additions & 8 deletions src/plugins/data/public/search/search_source/search_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import { filterDocvalueFields } from './filter_docvalue_fields';
import { fieldWildcardFilter } from '../../../../kibana_utils/public';
import { IIndexPattern, ISearchGeneric, SearchRequest } from '../..';
import { SearchSourceOptions, SearchSourceFields } from './types';
import { FetchOptions, RequestFailure, getSearchParams, handleResponse } from '../fetch';
import { FetchOptions, RequestFailure, handleResponse, getSearchParamsFromRequest } from '../fetch';

import { getEsQueryConfig, buildEsQuery, Filter, UI_SETTINGS } from '../../../common';
import { getHighlightRequest } from '../../../common/field_formats';
Expand Down Expand Up @@ -204,13 +204,12 @@ export class SearchSource {
*/
private fetch$(searchRequest: SearchRequest, signal?: AbortSignal) {
const { search, injectedMetadata, uiSettings } = this.dependencies;
const esShardTimeout = injectedMetadata.getInjectedVar('esShardTimeout') as number;
const searchParams = getSearchParams(uiSettings, esShardTimeout);
const params = {
index: searchRequest.index.title || searchRequest.index,
body: searchRequest.body,
...searchParams,
};

const params = getSearchParamsFromRequest(searchRequest, {
injectedMetadata,
uiSettings,
});

return search({ params, indexType: searchRequest.indexType }, { signal }).pipe(
map(({ rawResponse }) => handleResponse(searchRequest, rawResponse))
);
Expand Down
10 changes: 6 additions & 4 deletions src/plugins/vis_type_vega/public/__mocks__/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
import { CoreStart, IUiSettingsClient, NotificationsStart, SavedObjectsStart } from 'kibana/public';

import { createGetterSetter } from '../../../kibana_utils/public';
import { DataPublicPluginStart } from '../../../data/public';
import { IUiSettingsClient, NotificationsStart, SavedObjectsStart } from 'kibana/public';
import { dataPluginMock } from '../../../data/public/mocks';
import { coreMock } from '../../../../core/public/mocks';

Expand All @@ -34,22 +34,24 @@ setNotifications(coreMock.createStart().notifications);
export const [getUISettings, setUISettings] = createGetterSetter<IUiSettingsClient>('UISettings');
setUISettings(coreMock.createStart().uiSettings);

export const [getInjectedMetadata, setInjectedMetadata] = createGetterSetter<
CoreStart['injectedMetadata']
>('InjectedMetadata');
setInjectedMetadata(coreMock.createStart().injectedMetadata);

export const [getSavedObjects, setSavedObjects] = createGetterSetter<SavedObjectsStart>(
'SavedObjects'
);
setSavedObjects(coreMock.createStart().savedObjects);

export const [getInjectedVars, setInjectedVars] = createGetterSetter<{
esShardTimeout: number;
enableExternalUrls: boolean;
emsTileLayerId: unknown;
}>('InjectedVars');
setInjectedVars({
emsTileLayerId: {},
enableExternalUrls: true,
esShardTimeout: 10000,
});

export const getEsShardTimeout = () => getInjectedVars().esShardTimeout;
export const getEnableExternalUrls = () => getInjectedVars().enableExternalUrls;
export const getEmsTileLayerId = () => getInjectedVars().emsTileLayerId;
Loading

0 comments on commit 5d8de7a

Please sign in to comment.