diff --git a/src/core/server/saved_objects/service/lib/filter_utils.ts b/src/core/server/saved_objects/service/lib/filter_utils.ts index 9d796c279a770..55859f7108b26 100644 --- a/src/core/server/saved_objects/service/lib/filter_utils.ts +++ b/src/core/server/saved_objects/service/lib/filter_utils.ts @@ -21,7 +21,7 @@ import { get, set } from 'lodash'; import { SavedObjectsErrorHelpers } from './errors'; import { IndexMapping } from '../../mappings'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { esKuery } from '../../../../../plugins/data/server'; +import { esKuery, KueryNode } from '../../../../../plugins/data/server'; const astFunctionType = ['is', 'range', 'nested']; @@ -29,7 +29,7 @@ export const validateConvertFilterToKueryNode = ( allowedTypes: string[], filter: string, indexMapping: IndexMapping -): esKuery.KueryNode | undefined => { +): KueryNode | undefined => { if (filter && filter.length > 0 && indexMapping) { const filterKueryNode = esKuery.fromKueryExpression(filter); @@ -59,7 +59,7 @@ export const validateConvertFilterToKueryNode = ( validationFilterKuery.forEach(item => { const path: string[] = item.astPath.length === 0 ? [] : item.astPath.split('.'); - const existingKueryNode: esKuery.KueryNode = + const existingKueryNode: KueryNode = path.length === 0 ? filterKueryNode : get(filterKueryNode, path); if (item.isSavedObjectAttr) { existingKueryNode.arguments[0].value = existingKueryNode.arguments[0].value.split('.')[1]; @@ -95,7 +95,7 @@ interface ValidateFilterKueryNode { } interface ValidateFilterKueryNodeParams { - astFilter: esKuery.KueryNode; + astFilter: KueryNode; types: string[]; indexMapping: IndexMapping; hasNestedKey?: boolean; @@ -114,50 +114,47 @@ export const validateFilterKueryNode = ({ path = 'arguments', }: ValidateFilterKueryNodeParams): ValidateFilterKueryNode[] => { let localNestedKeys: string | undefined; - return astFilter.arguments.reduce( - (kueryNode: string[], ast: esKuery.KueryNode, index: number) => { - if (hasNestedKey && ast.type === 'literal' && ast.value != null) { - localNestedKeys = ast.value; - } - if (ast.arguments) { - const myPath = `${path}.${index}`; - return [ - ...kueryNode, - ...validateFilterKueryNode({ - astFilter: ast, + return astFilter.arguments.reduce((kueryNode: string[], ast: KueryNode, index: number) => { + if (hasNestedKey && ast.type === 'literal' && ast.value != null) { + localNestedKeys = ast.value; + } + if (ast.arguments) { + const myPath = `${path}.${index}`; + return [ + ...kueryNode, + ...validateFilterKueryNode({ + astFilter: ast, + types, + indexMapping, + storeValue: ast.type === 'function' && astFunctionType.includes(ast.function), + path: `${myPath}.arguments`, + hasNestedKey: ast.type === 'function' && ast.function === 'nested', + nestedKeys: localNestedKeys, + }), + ]; + } + if (storeValue && index === 0) { + const splitPath = path.split('.'); + return [ + ...kueryNode, + { + astPath: splitPath.slice(0, splitPath.length - 1).join('.'), + error: hasFilterKeyError( + nestedKeys != null ? `${nestedKeys}.${ast.value}` : ast.value, types, - indexMapping, - storeValue: ast.type === 'function' && astFunctionType.includes(ast.function), - path: `${myPath}.arguments`, - hasNestedKey: ast.type === 'function' && ast.function === 'nested', - nestedKeys: localNestedKeys, - }), - ]; - } - if (storeValue && index === 0) { - const splitPath = path.split('.'); - return [ - ...kueryNode, - { - astPath: splitPath.slice(0, splitPath.length - 1).join('.'), - error: hasFilterKeyError( - nestedKeys != null ? `${nestedKeys}.${ast.value}` : ast.value, - types, - indexMapping - ), - isSavedObjectAttr: isSavedObjectAttr( - nestedKeys != null ? `${nestedKeys}.${ast.value}` : ast.value, - indexMapping - ), - key: nestedKeys != null ? `${nestedKeys}.${ast.value}` : ast.value, - type: getType(nestedKeys != null ? `${nestedKeys}.${ast.value}` : ast.value), - }, - ]; - } - return kueryNode; - }, - [] - ); + indexMapping + ), + isSavedObjectAttr: isSavedObjectAttr( + nestedKeys != null ? `${nestedKeys}.${ast.value}` : ast.value, + indexMapping + ), + key: nestedKeys != null ? `${nestedKeys}.${ast.value}` : ast.value, + type: getType(nestedKeys != null ? `${nestedKeys}.${ast.value}` : ast.value), + }, + ]; + } + return kueryNode; + }, []); }; const getType = (key: string | undefined | null) => diff --git a/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts b/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts index 3fabad6af08ff..e6c06208ca1a5 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts @@ -17,7 +17,7 @@ * under the License. */ // eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { esKuery } from '../../../../../../plugins/data/server'; +import { esKuery, KueryNode } from '../../../../../../plugins/data/server'; import { getRootPropertiesObjects, IndexMapping } from '../../../mappings'; import { ISavedObjectTypeRegistry } from '../../../saved_objects_type_registry'; @@ -96,7 +96,7 @@ interface QueryParams { searchFields?: string[]; defaultSearchOperator?: string; hasReference?: HasReferenceQueryParams; - kueryNode?: esKuery.KueryNode; + kueryNode?: KueryNode; } /** diff --git a/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts b/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts index 75ab058a38be9..74c25491aff8b 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts @@ -23,7 +23,7 @@ import { IndexMapping } from '../../../mappings'; import { getQueryParams } from './query_params'; import { getSortingParams } from './sorting_params'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { esKuery } from '../../../../../../plugins/data/server'; +import { KueryNode } from '../../../../../../plugins/data/server'; import { ISavedObjectTypeRegistry } from '../../../saved_objects_type_registry'; interface GetSearchDslOptions { @@ -38,7 +38,7 @@ interface GetSearchDslOptions { type: string; id: string; }; - kueryNode?: esKuery.KueryNode; + kueryNode?: KueryNode; } export function getSearchDsl( diff --git a/src/plugins/data/common/es_query/index.ts b/src/plugins/data/common/es_query/index.ts index e585fda8aff80..4bfa20dfe7933 100644 --- a/src/plugins/data/common/es_query/index.ts +++ b/src/plugins/data/common/es_query/index.ts @@ -16,8 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -import * as esQuery from './es_query'; +export * from './es_query'; import * as esFilters from './filters'; -import * as esKuery from './kuery'; +export * from './kuery'; -export { esFilters, esQuery, esKuery }; +export { esFilters }; diff --git a/src/plugins/data/common/es_query/kuery/ast/ast.ts b/src/plugins/data/common/es_query/kuery/ast/ast.ts index 253f432617972..01ce77fa8f578 100644 --- a/src/plugins/data/common/es_query/kuery/ast/ast.ts +++ b/src/plugins/data/common/es_query/kuery/ast/ast.ts @@ -19,11 +19,12 @@ import { nodeTypes } from '../node_types/index'; import { KQLSyntaxError } from '../kuery_syntax_error'; -import { KueryNode, JsonObject, DslQuery, KueryParseOptions } from '../types'; +import { KueryNode, DslQuery, KueryParseOptions } from '../types'; import { IIndexPattern } from '../../../index_patterns/types'; // @ts-ignore import { parse as parseKuery } from './_generated_/kuery'; +import { JsonObject } from '../../../../../kibana_utils/public'; const fromExpression = ( expression: string | DslQuery, diff --git a/src/plugins/data/common/es_query/kuery/kuery_syntax_error.ts b/src/plugins/data/common/es_query/kuery/kuery_syntax_error.ts index 0d5cd6ea17f16..4ada139a10a0f 100644 --- a/src/plugins/data/common/es_query/kuery/kuery_syntax_error.ts +++ b/src/plugins/data/common/es_query/kuery/kuery_syntax_error.ts @@ -20,21 +20,21 @@ import { repeat } from 'lodash'; import { i18n } from '@kbn/i18n'; -const endOfInputText = i18n.translate('data.common.esQuery.kql.errors.endOfInputText', { +const endOfInputText = i18n.translate('data.common.kql.errors.endOfInputText', { defaultMessage: 'end of input', }); const grammarRuleTranslations: Record = { - fieldName: i18n.translate('data.common.esQuery.kql.errors.fieldNameText', { + fieldName: i18n.translate('data.common.kql.errors.fieldNameText', { defaultMessage: 'field name', }), - value: i18n.translate('data.common.esQuery.kql.errors.valueText', { + value: i18n.translate('data.common.kql.errors.valueText', { defaultMessage: 'value', }), - literal: i18n.translate('data.common.esQuery.kql.errors.literalText', { + literal: i18n.translate('data.common.kql.errors.literalText', { defaultMessage: 'literal', }), - whitespace: i18n.translate('data.common.esQuery.kql.errors.whitespaceText', { + whitespace: i18n.translate('data.common.kql.errors.whitespaceText', { defaultMessage: 'whitespace', }), }; @@ -61,7 +61,7 @@ export class KQLSyntaxError extends Error { const translatedExpectationText = translatedExpectations.join(', '); - message = i18n.translate('data.common.esQuery.kql.errors.syntaxError', { + message = i18n.translate('data.common.kql.errors.syntaxError', { defaultMessage: 'Expected {expectedList} but {foundInput} found.', values: { expectedList: translatedExpectationText, diff --git a/src/plugins/data/common/es_query/kuery/node_types/function.ts b/src/plugins/data/common/es_query/kuery/node_types/function.ts index 5b09bc2a67349..3137177fbfcc0 100644 --- a/src/plugins/data/common/es_query/kuery/node_types/function.ts +++ b/src/plugins/data/common/es_query/kuery/node_types/function.ts @@ -22,7 +22,7 @@ import _ from 'lodash'; import { functions } from '../functions'; import { IIndexPattern } from '../../..'; import { FunctionName, FunctionTypeBuildNode } from './types'; -import { JsonValue } from '..'; +import { JsonValue } from '../../../../../kibana_utils/public'; export function buildNode(functionName: FunctionName, ...args: any[]) { const kueryFunction = functions[functionName]; diff --git a/src/plugins/data/common/es_query/kuery/node_types/named_arg.ts b/src/plugins/data/common/es_query/kuery/node_types/named_arg.ts index 750801990f44e..398cb1a164415 100644 --- a/src/plugins/data/common/es_query/kuery/node_types/named_arg.ts +++ b/src/plugins/data/common/es_query/kuery/node_types/named_arg.ts @@ -21,7 +21,7 @@ import _ from 'lodash'; import * as ast from '../ast'; import { nodeTypes } from '../node_types'; import { NamedArgTypeBuildNode } from './types'; -import { JsonObject } from '../types'; +import { JsonObject } from '../../../../../kibana_utils/public'; export function buildNode(name: string, value: any): NamedArgTypeBuildNode { const argumentNode = diff --git a/src/plugins/data/common/es_query/kuery/node_types/types.ts b/src/plugins/data/common/es_query/kuery/node_types/types.ts index 1af4a20583d46..937b5c6e7ef9c 100644 --- a/src/plugins/data/common/es_query/kuery/node_types/types.ts +++ b/src/plugins/data/common/es_query/kuery/node_types/types.ts @@ -22,7 +22,8 @@ */ import { IIndexPattern } from '../../../index_patterns'; -import { JsonValue, KueryNode } from '..'; +import { JsonValue } from '../../../../../kibana_utils/public'; +import { KueryNode } from '..'; export type FunctionName = | 'is' diff --git a/src/plugins/data/common/es_query/kuery/types.ts b/src/plugins/data/common/es_query/kuery/types.ts index 63c52bb64dc65..086a1d97a2faf 100644 --- a/src/plugins/data/common/es_query/kuery/types.ts +++ b/src/plugins/data/common/es_query/kuery/types.ts @@ -38,10 +38,3 @@ export interface KueryParseOptions { } export { nodeTypes } from './node_types'; - -export type JsonArray = JsonValue[]; -export type JsonValue = null | boolean | number | string | JsonObject | JsonArray; - -export interface JsonObject { - [key: string]: JsonValue; -} diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index d7c90f3fd2a3f..0a6b4e38babd0 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -19,13 +19,44 @@ import { PluginInitializerContext } from '../../../core/public'; +/* + * esQuery and esKuery helper namespaces: + */ + +import { + doesKueryExpressionHaveLuceneSyntaxError, + fromKueryExpression, + toElasticsearchQuery, + nodeTypes, + buildEsQuery, + getEsQueryConfig, + buildQueryFromFilters, + luceneStringToDsl, + decorateQuery, +} from '../common'; + +export const esKuery = { + nodeTypes, + doesKueryExpressionHaveLuceneSyntaxError, + fromKueryExpression, + toElasticsearchQuery, +}; + +export const esQuery = { + buildEsQuery, + getEsQueryConfig, + buildQueryFromFilters, + luceneStringToDsl, + decorateQuery, +}; + /* * Field Formatters helper namespace: */ import { FieldFormat, - FieldFormatsRegistry, // exported only for tests. Consider mock. + FieldFormatsRegistry, DEFAULT_CONVERTER_COLOR, HTML_CONTEXT_TYPE, TEXT_CONTEXT_TYPE, @@ -84,6 +115,7 @@ export function plugin(initializerContext: PluginInitializerContext) { export { IRequestTypesMap, IResponseTypesMap } from './search'; export * from './types'; export { + EsQueryConfig, // index patterns IIndexPattern, IFieldType, @@ -123,8 +155,7 @@ export * from './field_formats'; export { // es query esFilters, - esKuery, - esQuery, + KueryNode, // index patterns isFilterable, // kbn field types diff --git a/src/plugins/data/public/search/search_source/search_source.ts b/src/plugins/data/public/search/search_source/search_source.ts index 1ebf9a8ca534c..95fbf069dcff0 100644 --- a/src/plugins/data/public/search/search_source/search_source.ts +++ b/src/plugins/data/public/search/search_source/search_source.ts @@ -73,12 +73,15 @@ import _ from 'lodash'; import { normalizeSortRequest } from './normalize_sort_request'; import { filterDocvalueFields } from './filter_docvalue_fields'; import { fieldWildcardFilter } from '../../../../kibana_utils/public'; -import { esFilters, esQuery, SearchRequest } from '../..'; + +import { esFilters, SearchRequest } from '../..'; + import { SearchSourceOptions, SearchSourceFields } from './types'; import { fetchSoon, FetchOptions, RequestFailure } from '../fetch'; import { getSearchService, getUiSettings, getInjectedMetadata } from '../../services'; -import { getHighlightRequest } from '../../../common'; +import { getEsQueryConfig, buildEsQuery } from '../../../common/es_query'; +import { getHighlightRequest } from '../../../common/field_formats'; export type ISearchSource = Pick; @@ -379,8 +382,8 @@ export class SearchSource { _.set(body, '_source.includes', remainingFields); } - const esQueryConfigs = esQuery.getEsQueryConfig(getUiSettings()); - body.query = esQuery.buildEsQuery(index, query, filters, esQueryConfigs); + const esQueryConfigs = getEsQueryConfig(getUiSettings()); + body.query = buildEsQuery(index, query, filters, esQueryConfigs); if (highlightAll && body.query) { body.highlight = getHighlightRequest(body.query, getUiSettings().get('doc_table:highlight')); diff --git a/src/plugins/data/public/ui/query_string_input/query_bar_top_row.tsx b/src/plugins/data/public/ui/query_string_input/query_bar_top_row.tsx index a3a9137e13e26..e2c396100dd5d 100644 --- a/src/plugins/data/public/ui/query_string_input/query_bar_top_row.tsx +++ b/src/plugins/data/public/ui/query_string_input/query_bar_top_row.tsx @@ -41,10 +41,10 @@ import { Query, PersistedLog, getQueryLog, - esKuery, } from '../..'; import { useKibana, toMountPoint } from '../../../../kibana_react/public'; import { QueryStringInput } from './query_string_input'; +import { doesKueryExpressionHaveLuceneSyntaxError } from '../../../common'; interface Props { query?: Query; @@ -298,7 +298,7 @@ function QueryBarTopRowUI(props: Props) { language === 'kuery' && typeof query === 'string' && (!storage || !storage.get('kibana.luceneSyntaxWarningOptOut')) && - esKuery.doesKueryExpressionHaveLuceneSyntaxError(query) + doesKueryExpressionHaveLuceneSyntaxError(query) ) { const toast = notifications!.toasts.addWarning({ title: intl.formatMessage({ diff --git a/src/plugins/data/server/index.ts b/src/plugins/data/server/index.ts index 1dc8528dbba67..cadb56da395d0 100644 --- a/src/plugins/data/server/index.ts +++ b/src/plugins/data/server/index.ts @@ -20,13 +20,36 @@ import { PluginInitializerContext } from '../../../core/server'; import { DataServerPlugin, DataPluginSetup, DataPluginStart } from './plugin'; +/* + * esQuery and esKuery helper namespaces: + */ + +import { + nodeTypes, + fromKueryExpression, + toElasticsearchQuery, + buildEsQuery, + getEsQueryConfig, +} from '../common'; + +export const esKuery = { + nodeTypes, + fromKueryExpression, + toElasticsearchQuery, +}; + +export const esQuery = { + getEsQueryConfig, + buildEsQuery, +}; + /* * Field Formatters helper namespace: */ import { + FieldFormatsRegistry, FieldFormat, - FieldFormatsRegistry, // exported only for tests. Consider mock. BoolFormat, BytesFormat, ColorFormat, @@ -45,8 +68,8 @@ import { } from '../common/field_formats'; export const fieldFormats = { + FieldFormatsRegistry, FieldFormat, - FieldFormatsRegistry, // exported only for tests. Consider mock. BoolFormat, BytesFormat, @@ -75,10 +98,10 @@ export function plugin(initializerContext: PluginInitializerContext) { export { IRequestTypesMap, IResponseTypesMap } from './search'; export { + EsQueryConfig, // es query esFilters, - esKuery, - esQuery, + KueryNode, // kbn field types castEsToKbnFieldTypeName, getKbnFieldType, diff --git a/src/plugins/kibana_utils/common/index.ts b/src/plugins/kibana_utils/common/index.ts index fb608a0db1ac2..4551d0e63c4be 100644 --- a/src/plugins/kibana_utils/common/index.ts +++ b/src/plugins/kibana_utils/common/index.ts @@ -21,5 +21,6 @@ export * from './defer'; export * from './of'; export * from './ui'; export * from './state_containers'; +export * from './typed_json'; export { createGetterSetter, Get, Set } from './create_getter_setter'; export { distinctUntilChangedWithInitialValue } from './distinct_until_changed_with_initial_value'; diff --git a/src/plugins/kibana_utils/common/typed_json.ts b/src/plugins/kibana_utils/common/typed_json.ts new file mode 100644 index 0000000000000..499037e27f38b --- /dev/null +++ b/src/plugins/kibana_utils/common/typed_json.ts @@ -0,0 +1,27 @@ +/* + * 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. + */ + +export type JsonValue = null | boolean | number | string | JsonObject | JsonArray; + +export interface JsonObject { + [key: string]: JsonValue; +} + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface JsonArray extends Array {} diff --git a/src/plugins/kibana_utils/public/index.ts b/src/plugins/kibana_utils/public/index.ts index 883f28da45223..6a285de12135b 100644 --- a/src/plugins/kibana_utils/public/index.ts +++ b/src/plugins/kibana_utils/public/index.ts @@ -26,6 +26,9 @@ export { Set, UiComponent, UiComponentInstance, + JsonValue, + JsonObject, + JsonArray, } from '../common'; export * from './core'; export * from './errors'; diff --git a/x-pack/legacy/plugins/graph/public/types/workspace_state.ts b/x-pack/legacy/plugins/graph/public/types/workspace_state.ts index 6a3f3146219ef..37a962fd569ce 100644 --- a/x-pack/legacy/plugins/graph/public/types/workspace_state.ts +++ b/x-pack/legacy/plugins/graph/public/types/workspace_state.ts @@ -6,15 +6,7 @@ import { FontawesomeIcon } from '../helpers/style_choices'; import { WorkspaceField, AdvancedSettings } from './app_state'; - -// eslint-disable-next-line @typescript-eslint/no-empty-interface -interface JsonArray extends Array {} - -type JsonValue = null | boolean | number | string | JsonObject | JsonArray; - -interface JsonObject { - [key: string]: JsonValue; -} +import { JsonObject } from '../../../../../../src/plugins/kibana_utils/public'; export interface WorkspaceNode { x: number; diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv_search.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv_search.ts index 1788cc60a23c0..9262d5910c247 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv_search.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv_search.ts @@ -26,6 +26,7 @@ import { getFilters } from './get_filters'; import { esQuery, + EsQueryConfig, esFilters, IIndexPattern, Query, @@ -45,7 +46,7 @@ const getEsQueryConfig = async (config: any) => { allowLeadingWildcards, queryStringOptions, ignoreFilterIfFieldNotInIndex, - } as esQuery.EsQueryConfig; + } as EsQueryConfig; }; const getUiSettings = async (config: any) => { diff --git a/x-pack/legacy/plugins/siem/common/typed_json.ts b/x-pack/legacy/plugins/siem/common/typed_json.ts index 646cf74d43bb1..dcd26d176d746 100644 --- a/x-pack/legacy/plugins/siem/common/typed_json.ts +++ b/x-pack/legacy/plugins/siem/common/typed_json.ts @@ -3,15 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ - -export type JsonValue = null | boolean | number | string | JsonObject | JsonArray; - -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface JsonArray extends Array {} - -export interface JsonObject { - [key: string]: JsonValue; -} +import { JsonObject } from '../../../../../src/plugins/kibana_utils/public'; export type ESQuery = ESRangeQuery | ESQueryStringQuery | ESMatchQuery | ESTermQuery | JsonObject; diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/helpers.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/helpers.test.tsx index efa70e640e2af..613afc742aace 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/helpers.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/helpers.test.tsx @@ -10,7 +10,7 @@ import { mockIndexPattern } from '../../mock'; import { mockDataProviders } from './data_providers/mock/mock_data_providers'; import { buildGlobalQuery, combineQueries } from './helpers'; import { mockBrowserFields } from '../../containers/source/mock'; -import { esQuery, esFilters } from '../../../../../../../src/plugins/data/public'; +import { EsQueryConfig, esFilters } from '../../../../../../../src/plugins/data/public'; const cleanUpKqlQuery = (str: string) => str.replace(/\n/g, '').replace(/\s\s+/g, ' '); const startDate = new Date('2018-03-23T18:49:23.132Z').valueOf(); @@ -116,7 +116,7 @@ describe('Build KQL Query', () => { }); describe('Combined Queries', () => { - const config: esQuery.EsQueryConfig = { + const config: EsQueryConfig = { allowLeadingWildcards: true, queryStringOptions: {}, ignoreFilterIfFieldNotInIndex: true, diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/helpers.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/helpers.tsx index 0f228a4d3df10..d4380738461bc 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/helpers.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/helpers.tsx @@ -14,7 +14,7 @@ import { BrowserFields } from '../../containers/source'; import { IIndexPattern, Query, - esQuery, + EsQueryConfig, esFilters, } from '../../../../../../../src/plugins/data/public'; @@ -105,7 +105,7 @@ export const combineQueries = ({ end, isEventViewer, }: { - config: esQuery.EsQueryConfig; + config: EsQueryConfig; dataProviders: DataProvider[]; indexPattern: IIndexPattern; browserFields: BrowserFields; diff --git a/x-pack/legacy/plugins/siem/public/lib/keury/index.ts b/x-pack/legacy/plugins/siem/public/lib/keury/index.ts index acd8b2d25f2ae..da7d03ebef621 100644 --- a/x-pack/legacy/plugins/siem/public/lib/keury/index.ts +++ b/x-pack/legacy/plugins/siem/public/lib/keury/index.ts @@ -6,6 +6,7 @@ import { isEmpty, isString, flow } from 'lodash/fp'; import { + EsQueryConfig, Query, esFilters, esQuery, @@ -13,6 +14,8 @@ import { IIndexPattern, } from '../../../../../../../src/plugins/data/public'; +import { JsonObject } from '../../../../../../../src/plugins/kibana_utils/public'; + import { KueryFilterQuery } from '../../store'; export const convertKueryToElasticSearchQuery = ( @@ -33,7 +36,7 @@ export const convertKueryToElasticSearchQuery = ( export const convertKueryToDslFilter = ( kueryExpression: string, indexPattern: IIndexPattern -): esKuery.JsonObject => { +): JsonObject => { try { return kueryExpression ? esKuery.toElasticsearchQuery(esKuery.fromKueryExpression(kueryExpression), indexPattern) @@ -87,7 +90,7 @@ export const convertToBuildEsQuery = ({ queries, filters, }: { - config: esQuery.EsQueryConfig; + config: EsQueryConfig; indexPattern: IIndexPattern; queries: Query[]; filters: esFilters.Filter[]; diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/helpers.ts b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/helpers.ts index 653f4978db305..f9ad2bdea4756 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/helpers.ts +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/helpers.ts @@ -5,8 +5,7 @@ */ import { get, isEmpty } from 'lodash/fp'; -import { esKuery } from '../../../../../../../../../src/plugins/data/common'; -import { esFilters } from '../../../../../../../../../src/plugins/data/public'; +import { esFilters, esKuery, KueryNode } from '../../../../../../../../../src/plugins/data/public'; import { DataProvider, DataProvidersAnd, @@ -34,7 +33,7 @@ const templateFields = [ ]; export const findValueToChangeInQuery = ( - keuryNode: esKuery.KueryNode, + keuryNode: KueryNode, valueToChange: FindValueToChangeInQuery[] = [] ): FindValueToChangeInQuery[] => { let localValueToChange = valueToChange; @@ -48,7 +47,7 @@ export const findValueToChangeInQuery = ( ]; } return keuryNode.arguments.reduce( - (addValueToChange: FindValueToChangeInQuery[], ast: esKuery.KueryNode) => { + (addValueToChange: FindValueToChangeInQuery[], ast: KueryNode) => { if (ast.function === 'is' && templateFields.includes(ast.arguments[0].value)) { return [ ...addValueToChange, diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/index.tsx index 7eb8e07ada762..4ee25066a9f4a 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/index.tsx @@ -11,8 +11,7 @@ import { connect } from 'react-redux'; import { Dispatch } from 'redux'; import { ActionCreator } from 'typescript-fsa'; -import { esFilters, esQuery } from '../../../../../../../../../src/plugins/data/common/es_query'; -import { Query } from '../../../../../../../../../src/plugins/data/common/query'; +import { esFilters, esQuery, Query } from '../../../../../../../../../src/plugins/data/public'; import { useFetchIndexPatterns } from '../../../../containers/detection_engine/rules/fetch_index_patterns'; import { StatefulEventsViewer } from '../../../../components/events_viewer'; import { HeaderSection } from '../../../../components/header_section'; diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals_histogram_panel/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals_histogram_panel/index.tsx index 4de471d6733cf..67b74712bc16c 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals_histogram_panel/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals_histogram_panel/index.tsx @@ -12,8 +12,7 @@ import { isEmpty } from 'lodash/fp'; import { HeaderSection } from '../../../../components/header_section'; import { SignalsHistogram } from './signals_histogram'; -import { Query } from '../../../../../../../../../src/plugins/data/common/query'; -import { esFilters, esQuery } from '../../../../../../../../../src/plugins/data/common/es_query'; +import { esFilters, esQuery, Query } from '../../../../../../../../../src/plugins/data/public'; import { RegisterQuery, SignalsHistogramOption, SignalsAggregation, SignalsTotal } from './types'; import { signalsHistogramOptions } from './config'; import { getDetectionEngineUrl } from '../../../../components/link_to'; diff --git a/x-pack/legacy/plugins/siem/server/utils/serialized_query.ts b/x-pack/legacy/plugins/siem/server/utils/serialized_query.ts index 6c8bef80d4fe9..1ba6eb8b9f9a6 100644 --- a/x-pack/legacy/plugins/siem/server/utils/serialized_query.ts +++ b/x-pack/legacy/plugins/siem/server/utils/serialized_query.ts @@ -7,7 +7,7 @@ import { UserInputError } from 'apollo-server-errors'; import { isEmpty, isPlainObject, isString } from 'lodash/fp'; -import { JsonObject } from '../../common/typed_json'; +import { JsonObject } from '../../../../../../src/plugins/kibana_utils/public'; export const parseFilterQuery = (filterQuery: string): JsonObject => { try { diff --git a/x-pack/legacy/plugins/uptime/public/hooks/update_kuery_string.ts b/x-pack/legacy/plugins/uptime/public/hooks/update_kuery_string.ts index 8a4ae01a72b4b..5fcacf8424660 100644 --- a/x-pack/legacy/plugins/uptime/public/hooks/update_kuery_string.ts +++ b/x-pack/legacy/plugins/uptime/public/hooks/update_kuery_string.ts @@ -5,8 +5,7 @@ */ import { combineFiltersAndUserSearch, stringifyKueries } from '../lib/helper'; -import { esKuery } from '../../../../../../src/plugins/data/common/es_query'; -import { IIndexPattern } from '../../../../../../src/plugins/data/common/index_patterns'; +import { esKuery, IIndexPattern } from '../../../../../../src/plugins/data/public'; const getKueryString = (urlFilters: string): string => { let kueryString = ''; diff --git a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/conjunction.test.ts b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/conjunction.test.ts index b0a3f64c6a479..211e0ad9a26c4 100644 --- a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/conjunction.test.ts +++ b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/conjunction.test.ts @@ -5,11 +5,10 @@ */ import { setupGetConjunctionSuggestions } from './conjunction'; -import { QuerySuggestionGetFnArgs, esKuery } from '../../../../../../../src/plugins/data/public'; +import { QuerySuggestionGetFnArgs, KueryNode } from '../../../../../../../src/plugins/data/public'; import { coreMock } from '../../../../../../../src/core/public/mocks'; -const mockKueryNode = (kueryNode: Partial) => - (kueryNode as unknown) as esKuery.KueryNode; +const mockKueryNode = (kueryNode: Partial) => (kueryNode as unknown) as KueryNode; describe('Kuery conjunction suggestions', () => { const querySuggestionsArgs = (null as unknown) as QuerySuggestionGetFnArgs; diff --git a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/field.test.ts b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/field.test.ts index 00262d092947b..09a2048e0b38b 100644 --- a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/field.test.ts +++ b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/field.test.ts @@ -9,12 +9,11 @@ import { setupGetFieldSuggestions } from './field'; import { isFilterable, QuerySuggestionGetFnArgs, - esKuery, + KueryNode, } from '../../../../../../../src/plugins/data/public'; import { coreMock } from '../../../../../../../src/core/public/mocks'; -const mockKueryNode = (kueryNode: Partial) => - (kueryNode as unknown) as esKuery.KueryNode; +const mockKueryNode = (kueryNode: Partial) => (kueryNode as unknown) as KueryNode; describe('Kuery field suggestions', () => { let querySuggestionsArgs: QuerySuggestionGetFnArgs; diff --git a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/operator.test.ts b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/operator.test.ts index 186d455a518b4..f7ffe1c2fec68 100644 --- a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/operator.test.ts +++ b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/operator.test.ts @@ -6,11 +6,10 @@ import indexPatternResponse from './__fixtures__/index_pattern_response.json'; import { setupGetOperatorSuggestions } from './operator'; -import { QuerySuggestionGetFnArgs, esKuery } from '../../../../../../../src/plugins/data/public'; +import { QuerySuggestionGetFnArgs, KueryNode } from '../../../../../../../src/plugins/data/public'; import { coreMock } from '../../../../../../../src/core/public/mocks'; -const mockKueryNode = (kueryNode: Partial) => - (kueryNode as unknown) as esKuery.KueryNode; +const mockKueryNode = (kueryNode: Partial) => (kueryNode as unknown) as KueryNode; describe('Kuery operator suggestions', () => { let getSuggestions: ReturnType; diff --git a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/types.ts b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/types.ts index eb7582fc6ec6b..eb596a44d9c51 100644 --- a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/types.ts +++ b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/types.ts @@ -6,14 +6,11 @@ import { CoreSetup } from 'kibana/public'; import { - esKuery, + KueryNode, QuerySuggestionBasic, QuerySuggestionGetFnArgs, } from '../../../../../../../src/plugins/data/public'; export type KqlQuerySuggestionProvider = ( core: CoreSetup -) => ( - querySuggestionsGetFnArgs: QuerySuggestionGetFnArgs, - kueryNode: esKuery.KueryNode -) => Promise; +) => (querySuggestionsGetFnArgs: QuerySuggestionGetFnArgs, kueryNode: KueryNode) => Promise; diff --git a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/value.test.ts b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/value.test.ts index 41fee5fa930fd..c40fa65d05d74 100644 --- a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/value.test.ts +++ b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/value.test.ts @@ -6,11 +6,10 @@ import { setupGetValueSuggestions } from './value'; import indexPatternResponse from './__fixtures__/index_pattern_response.json'; import { coreMock } from '../../../../../../../src/core/public/mocks'; -import { QuerySuggestionGetFnArgs, esKuery } from '../../../../../../../src/plugins/data/public'; +import { QuerySuggestionGetFnArgs, KueryNode } from '../../../../../../../src/plugins/data/public'; import { setAutocompleteService } from '../../../services'; -const mockKueryNode = (kueryNode: Partial) => - (kueryNode as unknown) as esKuery.KueryNode; +const mockKueryNode = (kueryNode: Partial) => (kueryNode as unknown) as KueryNode; describe('Kuery value suggestions', () => { let getSuggestions: ReturnType;