[Data][Es Query] Use ES types instead of DslQuery (#108290)
* es-query types * jest and lint * cc * options * type * type
This commit is contained in:
parent
fb215edf55
commit
e91baea5dc
|
@ -13,7 +13,7 @@ constructor(indexPattern: IndexPattern, configStates: Pick<Pick<{
|
|||
type: string;
|
||||
enabled?: boolean | undefined;
|
||||
id?: string | undefined;
|
||||
params?: {} | import("@kbn/common-utils").SerializableRecord | undefined;
|
||||
params?: {} | import("@kbn/utility-types").SerializableRecord | undefined;
|
||||
schema?: string | undefined;
|
||||
}, "schema" | "enabled" | "id" | "params"> & Pick<{
|
||||
type: string | IAggType;
|
||||
|
@ -27,6 +27,6 @@ constructor(indexPattern: IndexPattern, configStates: Pick<Pick<{
|
|||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| indexPattern | <code>IndexPattern</code> | |
|
||||
| configStates | <code>Pick<Pick<{</code><br/><code> type: string;</code><br/><code> enabled?: boolean | undefined;</code><br/><code> id?: string | undefined;</code><br/><code> params?: {} | import("@kbn/common-utils").SerializableRecord | undefined;</code><br/><code> schema?: string | undefined;</code><br/><code> }, "schema" | "enabled" | "id" | "params"> & Pick<{</code><br/><code> type: string | IAggType;</code><br/><code> }, "type"> & Pick<{</code><br/><code> type: string | IAggType;</code><br/><code> }, never>, "schema" | "type" | "enabled" | "id" | "params">[] | undefined</code> | |
|
||||
| configStates | <code>Pick<Pick<{</code><br/><code> type: string;</code><br/><code> enabled?: boolean | undefined;</code><br/><code> id?: string | undefined;</code><br/><code> params?: {} | import("@kbn/utility-types").SerializableRecord | undefined;</code><br/><code> schema?: string | undefined;</code><br/><code> }, "schema" | "enabled" | "id" | "params"> & Pick<{</code><br/><code> type: string | IAggType;</code><br/><code> }, "type"> & Pick<{</code><br/><code> type: string | IAggType;</code><br/><code> }, never>, "schema" | "type" | "enabled" | "id" | "params">[] | undefined</code> | |
|
||||
| opts | <code>AggConfigsOptions</code> | |
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ export declare type AggConfigSerialized = Ensure<{
|
|||
type: string;
|
||||
enabled?: boolean;
|
||||
id?: string;
|
||||
params?: {} | SerializableState;
|
||||
params?: {} | SerializableRecord;
|
||||
schema?: string;
|
||||
}, SerializableState>;
|
||||
}, SerializableRecord>;
|
||||
```
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
```typescript
|
||||
esKuery: {
|
||||
nodeTypes: import("@kbn/es-query/target_types/kuery/node_types").NodeTypes;
|
||||
fromKueryExpression: (expression: any, parseOptions?: Partial<import("@kbn/es-query/target_types/kuery/types").KueryParseOptions> | undefined) => import("@kbn/es-query").KueryNode;
|
||||
toElasticsearchQuery: (node: import("@kbn/es-query").KueryNode, indexPattern?: import("@kbn/es-query").IndexPatternBase | undefined, config?: Record<string, any> | undefined, context?: Record<string, any> | undefined) => import("@kbn/common-utils").JsonObject;
|
||||
fromKueryExpression: (expression: string | import("@elastic/elasticsearch/api/types").QueryDslQueryContainer, parseOptions?: Partial<import("@kbn/es-query/target_types/kuery/types").KueryParseOptions> | undefined) => import("@kbn/es-query").KueryNode;
|
||||
toElasticsearchQuery: (node: import("@kbn/es-query").KueryNode, indexPattern?: import("@kbn/es-query").IndexPatternBase | undefined, config?: Record<string, any> | undefined, context?: Record<string, any> | undefined) => import("@kbn/utility-types").JsonObject;
|
||||
}
|
||||
```
|
||||
|
|
|
@ -15,12 +15,7 @@
|
|||
esQuery: {
|
||||
buildEsQuery: typeof import("@kbn/es-query").buildEsQuery;
|
||||
getEsQueryConfig: typeof getEsQueryConfig;
|
||||
buildQueryFromFilters: (filters: import("@kbn/es-query").Filter[] | undefined, indexPattern: import("@kbn/es-query").IndexPatternBase | undefined, ignoreFilterIfFieldNotInIndex?: boolean | undefined) => {
|
||||
must: never[];
|
||||
filter: import("@kbn/es-query").Filter[];
|
||||
should: never[];
|
||||
must_not: import("@kbn/es-query").Filter[];
|
||||
};
|
||||
buildQueryFromFilters: (filters: import("@kbn/es-query").Filter[] | undefined, indexPattern: import("@kbn/es-query").IndexPatternBase | undefined, ignoreFilterIfFieldNotInIndex?: boolean | undefined) => import("@kbn/es-query").BoolQuery;
|
||||
luceneStringToDsl: typeof import("@kbn/es-query").luceneStringToDsl;
|
||||
decorateQuery: typeof import("@kbn/es-query").decorateQuery;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ export declare class FilterManager implements PersistableStateService
|
|||
| [getAllMigrations](./kibana-plugin-plugins-data-public.filtermanager.getallmigrations.md) | | <code>() => {}</code> | |
|
||||
| [inject](./kibana-plugin-plugins-data-public.filtermanager.inject.md) | | <code>any</code> | |
|
||||
| [migrateToLatest](./kibana-plugin-plugins-data-public.filtermanager.migratetolatest.md) | | <code>any</code> | |
|
||||
| [telemetry](./kibana-plugin-plugins-data-public.filtermanager.telemetry.md) | | <code>(filters: import("@kbn/common-utils").SerializableRecord, collector: unknown) => {}</code> | |
|
||||
| [telemetry](./kibana-plugin-plugins-data-public.filtermanager.telemetry.md) | | <code>(filters: import("@kbn/utility-types").SerializableRecord, collector: unknown) => {}</code> | |
|
||||
|
||||
## Methods
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
telemetry: (filters: import("@kbn/common-utils").SerializableRecord, collector: unknown) => {};
|
||||
telemetry: (filters: import("@kbn/utility-types").SerializableRecord, collector: unknown) => {};
|
||||
```
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
```typescript
|
||||
esKuery: {
|
||||
nodeTypes: import("@kbn/es-query/target_types/kuery/node_types").NodeTypes;
|
||||
fromKueryExpression: (expression: any, parseOptions?: Partial<import("@kbn/es-query/target_types/kuery/types").KueryParseOptions> | undefined) => import("@kbn/es-query").KueryNode;
|
||||
fromKueryExpression: (expression: string | import("@elastic/elasticsearch/api/types").QueryDslQueryContainer, parseOptions?: Partial<import("@kbn/es-query/target_types/kuery/types").KueryParseOptions> | undefined) => import("@kbn/es-query").KueryNode;
|
||||
toElasticsearchQuery: (node: import("@kbn/es-query").KueryNode, indexPattern?: import("@kbn/es-query").IndexPatternBase | undefined, config?: Record<string, any> | undefined, context?: Record<string, any> | undefined) => import("@kbn/utility-types").JsonObject;
|
||||
}
|
||||
```
|
||||
|
|
|
@ -8,12 +8,7 @@
|
|||
|
||||
```typescript
|
||||
esQuery: {
|
||||
buildQueryFromFilters: (filters: import("@kbn/es-query").Filter[] | undefined, indexPattern: import("@kbn/es-query").IndexPatternBase | undefined, ignoreFilterIfFieldNotInIndex?: boolean | undefined) => {
|
||||
must: never[];
|
||||
filter: import("@kbn/es-query").Filter[];
|
||||
should: never[];
|
||||
must_not: import("@kbn/es-query").Filter[];
|
||||
};
|
||||
buildQueryFromFilters: (filters: import("@kbn/es-query").Filter[] | undefined, indexPattern: import("@kbn/es-query").IndexPatternBase | undefined, ignoreFilterIfFieldNotInIndex?: boolean | undefined) => import("@kbn/es-query").BoolQuery;
|
||||
getEsQueryConfig: typeof getEsQueryConfig;
|
||||
buildEsQuery: typeof import("@kbn/es-query").buildEsQuery;
|
||||
}
|
||||
|
|
|
@ -702,7 +702,6 @@ function doSearch(
|
|||
const startTs = performance.now();
|
||||
|
||||
// Submit the search request using the `data.search` service.
|
||||
// @ts-expect-error request.params is incompatible. Filter is not assignable to QueryDslQueryContainer
|
||||
return data.search
|
||||
.search(req, { sessionId })
|
||||
.pipe(
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
*/
|
||||
|
||||
import { groupBy, has, isEqual } from 'lodash';
|
||||
import { SerializableRecord } from '@kbn/utility-types';
|
||||
import { buildQueryFromKuery } from './from_kuery';
|
||||
import { buildQueryFromFilters } from './from_filters';
|
||||
import { buildQueryFromLucene } from './from_lucene';
|
||||
import { Filter, Query } from '../filters';
|
||||
import { IndexPatternBase } from './types';
|
||||
import { BoolQuery, IndexPatternBase } from './types';
|
||||
import { KueryQueryOptions } from '../kuery';
|
||||
|
||||
/**
|
||||
|
@ -20,7 +21,7 @@ import { KueryQueryOptions } from '../kuery';
|
|||
*/
|
||||
export type EsQueryConfig = KueryQueryOptions & {
|
||||
allowLeadingWildcards: boolean;
|
||||
queryStringOptions: Record<string, any>;
|
||||
queryStringOptions: SerializableRecord;
|
||||
ignoreFilterIfFieldNotInIndex: boolean;
|
||||
};
|
||||
|
||||
|
@ -49,11 +50,11 @@ export function buildEsQuery(
|
|||
queryStringOptions: {},
|
||||
ignoreFilterIfFieldNotInIndex: false,
|
||||
}
|
||||
) {
|
||||
): { bool: BoolQuery } {
|
||||
queries = Array.isArray(queries) ? queries : [queries];
|
||||
filters = Array.isArray(filters) ? filters : [filters];
|
||||
|
||||
const validQueries = queries.filter((query: any) => has(query, 'query'));
|
||||
const validQueries = queries.filter((query) => has(query, 'query'));
|
||||
const queriesByLanguage = groupBy(validQueries, 'language');
|
||||
const kueryQuery = buildQueryFromKuery(
|
||||
indexPattern,
|
||||
|
|
|
@ -6,9 +6,11 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { SerializableRecord } from '@kbn/utility-types';
|
||||
import { extend, defaults } from 'lodash';
|
||||
import { getTimeZoneFromSettings } from '../utils';
|
||||
import { DslQuery, isEsQueryString } from './es_query_dsl';
|
||||
import { isEsQueryString } from './es_query_dsl';
|
||||
|
||||
/**
|
||||
* Decorate queries with default parameters
|
||||
|
@ -21,8 +23,8 @@ import { DslQuery, isEsQueryString } from './es_query_dsl';
|
|||
*/
|
||||
|
||||
export function decorateQuery(
|
||||
query: DslQuery,
|
||||
queryStringOptions: Record<string, any> | string,
|
||||
query: estypes.QueryDslQueryContainer,
|
||||
queryStringOptions: SerializableRecord | string,
|
||||
dateFormatTZ?: string
|
||||
) {
|
||||
if (isEsQueryString(query)) {
|
||||
|
|
|
@ -8,26 +8,6 @@
|
|||
|
||||
import { has } from 'lodash';
|
||||
|
||||
export interface DslRangeQuery {
|
||||
range: {
|
||||
[name: string]: {
|
||||
gte: number;
|
||||
lte: number;
|
||||
format: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface DslMatchQuery {
|
||||
match: {
|
||||
[name: string]: {
|
||||
query: string;
|
||||
operator: string;
|
||||
zero_terms_query: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface DslQueryStringQuery {
|
||||
query_string: {
|
||||
query: string;
|
||||
|
@ -35,24 +15,6 @@ export interface DslQueryStringQuery {
|
|||
};
|
||||
}
|
||||
|
||||
export interface DslMatchAllQuery {
|
||||
match_all: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface DslTermQuery {
|
||||
term: Record<string, string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export type DslQuery =
|
||||
| DslRangeQuery
|
||||
| DslMatchQuery
|
||||
| DslQueryStringQuery
|
||||
| DslMatchAllQuery
|
||||
| DslTermQuery;
|
||||
|
||||
/** @internal */
|
||||
export const isEsQueryString = (query: any): query is DslQueryStringQuery =>
|
||||
has(query, 'query_string.query');
|
||||
|
|
|
@ -7,10 +7,11 @@
|
|||
*/
|
||||
|
||||
import { isUndefined } from 'lodash';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { migrateFilter } from './migrate_filter';
|
||||
import { filterMatchesIndex } from './filter_matches_index';
|
||||
import { Filter, cleanFilter, isFilterDisabled } from '../filters';
|
||||
import { IndexPatternBase } from './types';
|
||||
import { BoolQuery, IndexPatternBase } from './types';
|
||||
import { handleNestedFilter } from './handle_nested_filter';
|
||||
|
||||
/**
|
||||
|
@ -33,20 +34,19 @@ const filterNegate = (reverse: boolean) => (filter: Filter) => {
|
|||
* @param {Object} filter - The filter to translate
|
||||
* @return {Object} the query version of that filter
|
||||
*/
|
||||
const translateToQuery = (filter: Filter) => {
|
||||
if (!filter) return;
|
||||
|
||||
const translateToQuery = (filter: Partial<Filter>): estypes.QueryDslQueryContainer => {
|
||||
if (filter.query) {
|
||||
return filter.query;
|
||||
}
|
||||
|
||||
return filter;
|
||||
// TODO: investigate what's going on here! What does this mean for filters that don't have a query!
|
||||
return filter as estypes.QueryDslQueryContainer;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param filters
|
||||
* @param indexPattern
|
||||
* @param ignoreFilterIfFieldNotInIndex by default filters that use fields that can't be found in the specified index pattern are not applied. Set this to true if you want to apply them any way.
|
||||
* @param ignoreFilterIfFieldNotInIndex by default filters that use fields that can't be found in the specified index pattern are not applied. Set this to true if you want to apply them anyway.
|
||||
* @returns An EQL query
|
||||
*
|
||||
* @public
|
||||
|
@ -55,11 +55,12 @@ export const buildQueryFromFilters = (
|
|||
filters: Filter[] = [],
|
||||
indexPattern: IndexPatternBase | undefined,
|
||||
ignoreFilterIfFieldNotInIndex: boolean = false
|
||||
) => {
|
||||
): BoolQuery => {
|
||||
filters = filters.filter((filter) => filter && !isFilterDisabled(filter));
|
||||
|
||||
const filtersToESQueries = (negate: boolean) => {
|
||||
return filters
|
||||
.filter((f) => !!f)
|
||||
.filter(filterNegate(negate))
|
||||
.filter(
|
||||
(filter) => !ignoreFilterIfFieldNotInIndex || filterMatchesIndex(filter, indexPattern)
|
||||
|
@ -68,8 +69,8 @@ export const buildQueryFromFilters = (
|
|||
return migrateFilter(filter, indexPattern);
|
||||
})
|
||||
.map((filter) => handleNestedFilter(filter, indexPattern))
|
||||
.map(translateToQuery)
|
||||
.map(cleanFilter);
|
||||
.map(cleanFilter)
|
||||
.map(translateToQuery);
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
@ -6,9 +6,10 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { SerializableRecord } from '@kbn/utility-types';
|
||||
import { Query } from '../filters';
|
||||
import { fromKueryExpression, toElasticsearchQuery, nodeTypes, KueryNode } from '../kuery';
|
||||
import { IndexPatternBase } from './types';
|
||||
import { BoolQuery, IndexPatternBase } from './types';
|
||||
|
||||
/** @internal */
|
||||
export function buildQueryFromKuery(
|
||||
|
@ -17,7 +18,7 @@ export function buildQueryFromKuery(
|
|||
allowLeadingWildcards: boolean = false,
|
||||
dateFormatTZ?: string,
|
||||
filtersInMustClause: boolean = false
|
||||
) {
|
||||
): BoolQuery {
|
||||
const queryASTs = queries.map((query) => {
|
||||
return fromKueryExpression(query.query, { allowLeadingWildcards });
|
||||
});
|
||||
|
@ -28,7 +29,7 @@ export function buildQueryFromKuery(
|
|||
function buildQuery(
|
||||
indexPattern: IndexPatternBase | undefined,
|
||||
queryASTs: KueryNode[],
|
||||
config: Record<string, any> = {}
|
||||
config: SerializableRecord = {}
|
||||
) {
|
||||
const compoundQueryAST = nodeTypes.function.buildNode('and', queryASTs);
|
||||
const kueryQuery = toElasticsearchQuery(compoundQueryAST, indexPattern, config);
|
||||
|
|
|
@ -6,16 +6,18 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { SerializableRecord } from '@kbn/utility-types';
|
||||
import { Query } from '..';
|
||||
import { decorateQuery } from './decorate_query';
|
||||
import { luceneStringToDsl } from './lucene_string_to_dsl';
|
||||
import { BoolQuery } from './types';
|
||||
|
||||
/** @internal */
|
||||
export function buildQueryFromLucene(
|
||||
queries: Query[],
|
||||
queryStringOptions: Record<string, any>,
|
||||
queryStringOptions: SerializableRecord,
|
||||
dateFormatTZ?: string
|
||||
) {
|
||||
): BoolQuery {
|
||||
const combinedQueries = (queries || []).map((query) => {
|
||||
const queryDsl = luceneStringToDsl(query.query);
|
||||
|
||||
|
|
|
@ -10,4 +10,4 @@ export { buildEsQuery, EsQueryConfig } from './build_es_query';
|
|||
export { buildQueryFromFilters } from './from_filters';
|
||||
export { luceneStringToDsl } from './lucene_string_to_dsl';
|
||||
export { decorateQuery } from './decorate_query';
|
||||
export { IndexPatternBase, IndexPatternFieldBase, IFieldSubType } from './types';
|
||||
export { IndexPatternBase, IndexPatternFieldBase, IFieldSubType, BoolQuery } from './types';
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { isString } from 'lodash';
|
||||
import { DslQuery } from './es_query_dsl';
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -16,7 +16,9 @@ import { DslQuery } from './es_query_dsl';
|
|||
*
|
||||
* @public
|
||||
*/
|
||||
export function luceneStringToDsl(query: string | any): DslQuery {
|
||||
export function luceneStringToDsl(
|
||||
query: string | estypes.QueryDslQueryContainer
|
||||
): estypes.QueryDslQueryContainer {
|
||||
if (isString(query)) {
|
||||
if (query.trim() === '') {
|
||||
return { match_all: {} };
|
||||
|
|
|
@ -23,7 +23,7 @@ export interface DeprecatedMatchPhraseFilter extends Filter {
|
|||
};
|
||||
}
|
||||
|
||||
function isDeprecatedMatchPhraseFilter(filter: any): filter is DeprecatedMatchPhraseFilter {
|
||||
function isDeprecatedMatchPhraseFilter(filter: Filter): filter is DeprecatedMatchPhraseFilter {
|
||||
const fieldName = filter.query && filter.query.match && Object.keys(filter.query.match)[0];
|
||||
|
||||
return Boolean(fieldName && get(filter, ['query', 'match', fieldName, 'type']) === 'phrase');
|
||||
|
|
|
@ -49,3 +49,10 @@ export interface IndexPatternBase {
|
|||
id?: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
export interface BoolQuery {
|
||||
must: estypes.QueryDslQueryContainer[];
|
||||
must_not: estypes.QueryDslQueryContainer[];
|
||||
filter: estypes.QueryDslQueryContainer[];
|
||||
should: estypes.QueryDslQueryContainer[];
|
||||
}
|
||||
|
|
|
@ -135,4 +135,4 @@ export const isFilters = (x: unknown): x is Filter[] =>
|
|||
*
|
||||
* @public
|
||||
*/
|
||||
export const cleanFilter = (filter: Filter): Filter => omit(filter, ['meta', '$state']) as Filter;
|
||||
export const cleanFilter = (filter: Filter): Partial<Filter> => omit(filter, ['meta', '$state']);
|
||||
|
|
|
@ -7,15 +7,16 @@
|
|||
*/
|
||||
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { nodeTypes } from '../node_types/index';
|
||||
import { KQLSyntaxError } from '../kuery_syntax_error';
|
||||
import { KueryNode, DslQuery, KueryParseOptions } from '../types';
|
||||
import { KueryNode, KueryParseOptions } from '../types';
|
||||
|
||||
import { parse as parseKuery } from '../grammar';
|
||||
import { IndexPatternBase } from '../..';
|
||||
|
||||
const fromExpression = (
|
||||
expression: string | DslQuery,
|
||||
expression: string | estypes.QueryDslQueryContainer,
|
||||
parseOptions: Partial<KueryParseOptions> = {},
|
||||
parse: Function = parseKuery
|
||||
): KueryNode => {
|
||||
|
@ -27,7 +28,7 @@ const fromExpression = (
|
|||
};
|
||||
|
||||
export const fromLiteralExpression = (
|
||||
expression: string | DslQuery,
|
||||
expression: string | estypes.QueryDslQueryContainer,
|
||||
parseOptions: Partial<KueryParseOptions> = {}
|
||||
): KueryNode => {
|
||||
return fromExpression(
|
||||
|
@ -41,7 +42,7 @@ export const fromLiteralExpression = (
|
|||
};
|
||||
|
||||
export const fromKueryExpression = (
|
||||
expression: string | DslQuery,
|
||||
expression: string | estypes.QueryDslQueryContainer,
|
||||
parseOptions: Partial<KueryParseOptions> = {}
|
||||
): KueryNode => {
|
||||
try {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { NodeTypes } from './node_types';
|
||||
|
||||
/** @public */
|
||||
|
@ -15,10 +16,9 @@ export interface KueryNode {
|
|||
}
|
||||
|
||||
/**
|
||||
* TODO: Replace with real type
|
||||
* @public
|
||||
*/
|
||||
export type DslQuery = any;
|
||||
export type DslQuery = estypes.QueryDslQueryContainer;
|
||||
|
||||
/** @internal */
|
||||
export interface KueryParseOptions {
|
||||
|
|
|
@ -791,7 +791,7 @@ export const esFilters: {
|
|||
// @public @deprecated (undocumented)
|
||||
export const esKuery: {
|
||||
nodeTypes: import("@kbn/es-query/target_types/kuery/node_types").NodeTypes;
|
||||
fromKueryExpression: (expression: any, parseOptions?: Partial<import("@kbn/es-query/target_types/kuery/types").KueryParseOptions> | undefined) => import("@kbn/es-query").KueryNode;
|
||||
fromKueryExpression: (expression: string | import("@elastic/elasticsearch/api/types").QueryDslQueryContainer, parseOptions?: Partial<import("@kbn/es-query/target_types/kuery/types").KueryParseOptions> | undefined) => import("@kbn/es-query").KueryNode;
|
||||
toElasticsearchQuery: (node: import("@kbn/es-query").KueryNode, indexPattern?: import("@kbn/es-query").IndexPatternBase | undefined, config?: Record<string, any> | undefined, context?: Record<string, any> | undefined) => import("@kbn/utility-types").JsonObject;
|
||||
};
|
||||
|
||||
|
@ -801,12 +801,7 @@ export const esKuery: {
|
|||
export const esQuery: {
|
||||
buildEsQuery: typeof import("@kbn/es-query").buildEsQuery;
|
||||
getEsQueryConfig: typeof getEsQueryConfig;
|
||||
buildQueryFromFilters: (filters: import("@kbn/es-query").Filter[] | undefined, indexPattern: import("@kbn/es-query").IndexPatternBase | undefined, ignoreFilterIfFieldNotInIndex?: boolean | undefined) => {
|
||||
must: never[];
|
||||
filter: import("@kbn/es-query").Filter[];
|
||||
should: never[];
|
||||
must_not: import("@kbn/es-query").Filter[];
|
||||
};
|
||||
buildQueryFromFilters: (filters: import("@kbn/es-query").Filter[] | undefined, indexPattern: import("@kbn/es-query").IndexPatternBase | undefined, ignoreFilterIfFieldNotInIndex?: boolean | undefined) => import("@kbn/es-query").BoolQuery;
|
||||
luceneStringToDsl: typeof import("@kbn/es-query").luceneStringToDsl;
|
||||
decorateQuery: typeof import("@kbn/es-query").decorateQuery;
|
||||
};
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
*/
|
||||
|
||||
import { compact, flatten } from 'lodash';
|
||||
import { Filter } from '@kbn/es-query';
|
||||
import { mapFilter } from './map_filter';
|
||||
import { Filter } from '../../../../common';
|
||||
|
||||
export const mapAndFlattenFilters = (filters: Filter[]) => {
|
||||
return compact(flatten(filters)).map((item: Filter) => mapFilter(item));
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
import { reduceRight } from 'lodash';
|
||||
|
||||
import { Filter } from '@kbn/es-query';
|
||||
import { mapSpatialFilter } from './mappers/map_spatial_filter';
|
||||
import { mapMatchAll } from './mappers/map_match_all';
|
||||
import { mapPhrase } from './mappers/map_phrase';
|
||||
|
@ -20,7 +21,6 @@ import { mapGeoBoundingBox } from './mappers/map_geo_bounding_box';
|
|||
import { mapGeoPolygon } from './mappers/map_geo_polygon';
|
||||
import { mapDefault } from './mappers/map_default';
|
||||
import { generateMappingChain } from './generate_mapping_chain';
|
||||
import { Filter } from '../../../../common';
|
||||
|
||||
export function mapFilter(filter: Filter) {
|
||||
/** Mappers **/
|
||||
|
|
|
@ -124,7 +124,7 @@ export const esFilters: {
|
|||
// @public (undocumented)
|
||||
export const esKuery: {
|
||||
nodeTypes: import("@kbn/es-query/target_types/kuery/node_types").NodeTypes;
|
||||
fromKueryExpression: (expression: any, parseOptions?: Partial<import("@kbn/es-query/target_types/kuery/types").KueryParseOptions> | undefined) => import("@kbn/es-query").KueryNode;
|
||||
fromKueryExpression: (expression: string | import("@elastic/elasticsearch/api/types").QueryDslQueryContainer, parseOptions?: Partial<import("@kbn/es-query/target_types/kuery/types").KueryParseOptions> | undefined) => import("@kbn/es-query").KueryNode;
|
||||
toElasticsearchQuery: (node: import("@kbn/es-query").KueryNode, indexPattern?: import("@kbn/es-query").IndexPatternBase | undefined, config?: Record<string, any> | undefined, context?: Record<string, any> | undefined) => import("@kbn/utility-types").JsonObject;
|
||||
};
|
||||
|
||||
|
@ -132,12 +132,7 @@ export const esKuery: {
|
|||
//
|
||||
// @public (undocumented)
|
||||
export const esQuery: {
|
||||
buildQueryFromFilters: (filters: import("@kbn/es-query").Filter[] | undefined, indexPattern: import("@kbn/es-query").IndexPatternBase | undefined, ignoreFilterIfFieldNotInIndex?: boolean | undefined) => {
|
||||
must: never[];
|
||||
filter: import("@kbn/es-query").Filter[];
|
||||
should: never[];
|
||||
must_not: import("@kbn/es-query").Filter[];
|
||||
};
|
||||
buildQueryFromFilters: (filters: import("@kbn/es-query").Filter[] | undefined, indexPattern: import("@kbn/es-query").IndexPatternBase | undefined, ignoreFilterIfFieldNotInIndex?: boolean | undefined) => import("@kbn/es-query").BoolQuery;
|
||||
getEsQueryConfig: typeof getEsQueryConfig;
|
||||
buildEsQuery: typeof import("@kbn/es-query").buildEsQuery;
|
||||
};
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import type { estypes } from '@elastic/elasticsearch';
|
||||
import { DslQuery, Filter } from '@kbn/es-query';
|
||||
import { Assign } from '@kbn/utility-types';
|
||||
import { Spec } from 'vega';
|
||||
import { EsQueryParser } from './es_query_parser';
|
||||
|
@ -143,10 +142,10 @@ export interface TimeBucket {
|
|||
export interface Bool {
|
||||
[index: string]: any;
|
||||
bool?: Bool;
|
||||
must?: DslQuery[];
|
||||
filter?: Filter[];
|
||||
should?: Filter[];
|
||||
must_not?: Filter[];
|
||||
must?: estypes.QueryDslQueryContainer[];
|
||||
filter?: estypes.QueryDslQueryContainer[];
|
||||
should?: estypes.QueryDslQueryContainer[];
|
||||
must_not?: estypes.QueryDslQueryContainer[];
|
||||
}
|
||||
|
||||
export interface Query {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import * as rt from 'io-ts';
|
||||
import { DslQuery } from '@kbn/es-query';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { logSourceColumnConfigurationRT } from '../../log_sources/log_source_configuration';
|
||||
import {
|
||||
logEntryAfterCursorRT,
|
||||
|
@ -14,7 +14,7 @@ import {
|
|||
logEntryCursorRT,
|
||||
logEntryRT,
|
||||
} from '../../log_entry';
|
||||
import { JsonObject, jsonObjectRT } from '../../typed_json';
|
||||
import { jsonObjectRT } from '../../typed_json';
|
||||
import { searchStrategyErrorRT } from '../common/errors';
|
||||
|
||||
export const LOG_ENTRIES_SEARCH_STRATEGY = 'infra-log-entries';
|
||||
|
@ -51,7 +51,7 @@ export const logEntriesSearchRequestParamsRT = rt.union([
|
|||
|
||||
export type LogEntriesSearchRequestParams = rt.TypeOf<typeof logEntriesSearchRequestParamsRT>;
|
||||
|
||||
export type LogEntriesSearchRequestQuery = JsonObject | DslQuery;
|
||||
export type LogEntriesSearchRequestQuery = estypes.QueryDslQueryContainer;
|
||||
|
||||
export const logEntriesSearchResponsePayloadRT = rt.intersection([
|
||||
rt.type({
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import { useCallback } from 'react';
|
||||
import { Observable } from 'rxjs';
|
||||
import { exhaustMap } from 'rxjs/operators';
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
import { IKibanaSearchRequest } from '../../../../../../../src/plugins/data/public';
|
||||
import { LogSourceColumnConfiguration } from '../../../../common/log_sources';
|
||||
import { LogEntryAfterCursor } from '../../../../common/log_entry';
|
||||
|
@ -55,7 +56,7 @@ export const useLogEntriesAfterRequest = ({
|
|||
columns: columnOverrides,
|
||||
endTimestamp: params?.extendTo ?? endTimestamp,
|
||||
highlightPhrase,
|
||||
query,
|
||||
query: query as JsonObject,
|
||||
size: params.size,
|
||||
sourceId,
|
||||
startTimestamp,
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import { useCallback } from 'react';
|
||||
import { Observable } from 'rxjs';
|
||||
import { exhaustMap } from 'rxjs/operators';
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
import { IKibanaSearchRequest } from '../../../../../../../src/plugins/data/public';
|
||||
import { LogSourceColumnConfiguration } from '../../../../common/log_sources';
|
||||
import { LogEntryBeforeCursor } from '../../../../common/log_entry';
|
||||
|
@ -57,7 +58,7 @@ export const useLogEntriesBeforeRequest = ({
|
|||
columns: columnOverrides,
|
||||
endTimestamp,
|
||||
highlightPhrase,
|
||||
query,
|
||||
query: query as JsonObject,
|
||||
size: params.size,
|
||||
sourceId,
|
||||
startTimestamp: params.extendTo ?? startTimestamp,
|
||||
|
|
|
@ -76,7 +76,6 @@ export const findListItem = async ({
|
|||
|
||||
const { body: respose } = await esClient.count({
|
||||
body: {
|
||||
// @ts-expect-error GetQueryFilterReturn is not assignable to QueryDslQueryContainer
|
||||
query,
|
||||
},
|
||||
ignore_unavailable: true,
|
||||
|
@ -89,7 +88,6 @@ export const findListItem = async ({
|
|||
// to explicitly define the type <T>.
|
||||
const { body: response } = await esClient.search<SearchEsListItemSchema>({
|
||||
body: {
|
||||
// @ts-expect-error GetQueryFilterReturn is not assignable to QueryDslQueryContainer
|
||||
query,
|
||||
search_after: scroll.searchAfter,
|
||||
sort: getSortWithTieBreaker({ sortField, sortOrder }),
|
||||
|
|
|
@ -65,7 +65,6 @@ export const findList = async ({
|
|||
|
||||
const { body: totalCount } = await esClient.count({
|
||||
body: {
|
||||
// @ts-expect-error GetQueryFilterReturn is not compatible with QueryDslQueryContainer
|
||||
query,
|
||||
},
|
||||
ignore_unavailable: true,
|
||||
|
@ -78,7 +77,6 @@ export const findList = async ({
|
|||
// to explicitly define the type <T>.
|
||||
const { body: response } = await esClient.search<SearchEsListSchema>({
|
||||
body: {
|
||||
// @ts-expect-error GetQueryFilterReturn is not compatible with QueryDslQueryContainer
|
||||
query,
|
||||
search_after: scroll.searchAfter,
|
||||
sort: getSortWithTieBreaker({ sortField, sortOrder }),
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { DslQuery, EsQueryConfig } from '@kbn/es-query';
|
||||
|
||||
import { Filter, Query, esQuery } from '../../../../../../src/plugins/data/server';
|
||||
import { BoolQuery, EsQueryConfig, Query, buildEsQuery } from '@kbn/es-query';
|
||||
|
||||
import { escapeQuotes } from './escape_query';
|
||||
|
||||
|
@ -21,7 +19,7 @@ export interface GetQueryFilterWithListIdOptions {
|
|||
}
|
||||
|
||||
export interface GetQueryFilterReturn {
|
||||
bool: { must: DslQuery[]; filter: Filter[]; should: never[]; must_not: Filter[] };
|
||||
bool: BoolQuery;
|
||||
}
|
||||
|
||||
export const getQueryFilter = ({ filter }: GetQueryFilterOptions): GetQueryFilterReturn => {
|
||||
|
@ -36,7 +34,7 @@ export const getQueryFilter = ({ filter }: GetQueryFilterOptions): GetQueryFilte
|
|||
queryStringOptions: { analyze_wildcard: true },
|
||||
};
|
||||
|
||||
return esQuery.buildEsQuery(undefined, kqlQuery, [], config);
|
||||
return buildEsQuery(undefined, kqlQuery, [], config);
|
||||
};
|
||||
|
||||
export const getQueryFilterWithListId = ({
|
||||
|
|
|
@ -46,7 +46,6 @@ export const getSearchAfterScroll = async <T>({
|
|||
const { body: response } = await esClient.search<TieBreaker<T>>({
|
||||
body: {
|
||||
_source: getSourceWithTieBreaker({ sortField }),
|
||||
// @ts-expect-error Filter is not assignale to QueryDslQueryContainer
|
||||
query,
|
||||
search_after: newSearchAfter,
|
||||
sort: getSortWithTieBreaker({ sortField, sortOrder }),
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { estypes } from '@elastic/elasticsearch';
|
||||
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
import { buildEsQuery, DslQuery } from '@kbn/es-query';
|
||||
import { buildEsQuery } from '@kbn/es-query';
|
||||
|
||||
import { isPopulatedObject } from '../util/object_utils';
|
||||
|
||||
|
@ -26,4 +26,7 @@ export const ES_CLIENT_TOTAL_HITS_RELATION: Record<
|
|||
GTE: 'gte',
|
||||
} as const;
|
||||
|
||||
export type InfluencersFilterQuery = ReturnType<typeof buildEsQuery> | DslQuery | JsonObject;
|
||||
export type InfluencersFilterQuery =
|
||||
| ReturnType<typeof buildEsQuery>
|
||||
| estypes.QueryDslQueryContainer
|
||||
| JsonObject;
|
||||
|
|
|
@ -58,9 +58,9 @@ export function getKqlQueryValues({
|
|||
influencersFilterQuery = esQuery.luceneStringToDsl(inputString);
|
||||
}
|
||||
|
||||
const clearSettings =
|
||||
influencersFilterQuery?.match_all && Object.keys(influencersFilterQuery.match_all).length === 0;
|
||||
|
||||
const clearSettings = Boolean(
|
||||
influencersFilterQuery?.match_all && Object.keys(influencersFilterQuery.match_all).length === 0
|
||||
);
|
||||
return {
|
||||
clearSettings,
|
||||
settings: {
|
||||
|
|
|
@ -36,7 +36,7 @@ export interface ExplorerState {
|
|||
filteredFields: any[];
|
||||
filterPlaceHolder: any;
|
||||
indexPattern: { title: string; fields: any[] };
|
||||
influencersFilterQuery: InfluencersFilterQuery;
|
||||
influencersFilterQuery?: InfluencersFilterQuery;
|
||||
influencers: Dictionary<any>;
|
||||
isAndOperator: boolean;
|
||||
loading: boolean;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { SerializableRecord } from '@kbn/utility-types';
|
||||
import { createAction } from '../../../../../src/plugins/ui_actions/public';
|
||||
import { MlCoreSetup } from '../plugin';
|
||||
import { ML_APP_LOCATOR } from '../../common/constants/locator';
|
||||
|
@ -103,7 +104,7 @@ export function createOpenInExplorerAction(getStartServices: MlCoreSetup['getSta
|
|||
pageState: {
|
||||
jobIds,
|
||||
timeRange,
|
||||
...(mlExplorerFilter ? { mlExplorerFilter } : {}),
|
||||
...(mlExplorerFilter ? ({ mlExplorerFilter } as SerializableRecord) : {}),
|
||||
query: {},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { DslQuery, Filter } from '@kbn/es-query';
|
||||
import { BoolQuery } from '@kbn/es-query';
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
|
||||
export type ESQuery =
|
||||
|
@ -48,10 +48,5 @@ export interface ESTermQuery {
|
|||
}
|
||||
|
||||
export interface ESBoolQuery {
|
||||
bool: {
|
||||
must: DslQuery[];
|
||||
filter: Filter[];
|
||||
should: never[];
|
||||
must_not: Filter[];
|
||||
};
|
||||
bool: BoolQuery;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { DslQuery, Filter } from '@kbn/es-query';
|
||||
|
||||
import { BoolQuery } from '@kbn/es-query';
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
|
||||
export type ESQuery =
|
||||
|
@ -49,10 +48,5 @@ export interface ESTermQuery {
|
|||
}
|
||||
|
||||
export interface ESBoolQuery {
|
||||
bool: {
|
||||
must: DslQuery[];
|
||||
filter: Filter[];
|
||||
should: never[];
|
||||
must_not: Filter[];
|
||||
};
|
||||
bool: BoolQuery;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,6 @@ export const getThreatList = async ({
|
|||
);
|
||||
const { body: response } = await esClient.search<ThreatListDoc>({
|
||||
body: {
|
||||
// @ts-expect-error ESBoolQuery is not assignale to QueryDslQueryContainer
|
||||
query: queryFilter,
|
||||
fields: [
|
||||
{
|
||||
|
@ -126,7 +125,6 @@ export const getThreatListCount = async ({
|
|||
);
|
||||
const { body: response } = await esClient.count({
|
||||
body: {
|
||||
// @ts-expect-error ESBoolQuery is not assignale to QueryDslQueryContainer
|
||||
query: queryFilter,
|
||||
},
|
||||
ignore_unavailable: true,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import type { estypes } from '@elastic/elasticsearch';
|
||||
import { DslQuery, Filter } from '@kbn/es-query';
|
||||
import { BoolQuery } from '@kbn/es-query';
|
||||
import moment from 'moment';
|
||||
import type { ExceptionListItemSchema } from '@kbn/securitysolution-io-ts-list-types';
|
||||
import { Status } from '../../../../common/detection_engine/schemas/common/schemas';
|
||||
|
@ -274,12 +274,7 @@ export type BulkResponseErrorAggregation = Record<string, { count: number; statu
|
|||
* TODO: Remove this if/when the return filter has its own type exposed
|
||||
*/
|
||||
export interface QueryFilter {
|
||||
bool: {
|
||||
must: DslQuery[];
|
||||
filter: Filter[];
|
||||
should: unknown[];
|
||||
must_not: Filter[];
|
||||
};
|
||||
bool: BoolQuery;
|
||||
}
|
||||
|
||||
export type SignalsEnrichment = (signals: SignalSearchResponse) => Promise<SignalSearchResponse>;
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
|
||||
import { DslQuery, Filter } from '@kbn/es-query';
|
||||
import { BoolQuery } from '@kbn/es-query';
|
||||
|
||||
export type ESQuery =
|
||||
| ESRangeQuery
|
||||
|
@ -48,10 +47,5 @@ export interface ESTermQuery {
|
|||
}
|
||||
|
||||
export interface ESBoolQuery {
|
||||
bool: {
|
||||
must: DslQuery[];
|
||||
filter: Filter[];
|
||||
should: never[];
|
||||
must_not: Filter[];
|
||||
};
|
||||
bool: BoolQuery;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue