[Data][Es Query] Use ES types in Kuery functions (#108367)
* es-query types * jest and lint * cc * options * type * types for kuery FUNCTIONS * doc * sec fixes * typey type * test typescript * test * fixes * test * cr * cleanup a bit more Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
e258f46167
commit
9d1a8a87f8
|
@ -15,6 +15,6 @@
|
|||
esKuery: {
|
||||
nodeTypes: import("@kbn/es-query/target_types/kuery/node_types").NodeTypes;
|
||||
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;
|
||||
toElasticsearchQuery: (node: import("@kbn/es-query").KueryNode, indexPattern?: import("@kbn/es-query").IndexPatternBase | undefined, config?: import("@kbn/es-query").KueryQueryOptions | undefined, context?: Record<string, any> | undefined) => import("@elastic/elasticsearch/api/types").QueryDslQueryContainer;
|
||||
}
|
||||
```
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
esKuery: {
|
||||
nodeTypes: import("@kbn/es-query/target_types/kuery/node_types").NodeTypes;
|
||||
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;
|
||||
toElasticsearchQuery: (node: import("@kbn/es-query").KueryNode, indexPattern?: import("@kbn/es-query").IndexPatternBase | undefined, config?: import("@kbn/es-query").KueryQueryOptions | undefined, context?: Record<string, any> | undefined) => import("@elastic/elasticsearch/api/types").QueryDslQueryContainer;
|
||||
}
|
||||
```
|
||||
|
|
|
@ -30,7 +30,7 @@ function buildQuery(
|
|||
indexPattern: IndexPatternBase | undefined,
|
||||
queryASTs: KueryNode[],
|
||||
config: SerializableRecord = {}
|
||||
) {
|
||||
): BoolQuery {
|
||||
const compoundQueryAST = nodeTypes.function.buildNode('and', queryASTs);
|
||||
const kueryQuery = toElasticsearchQuery(compoundQueryAST, indexPattern, config);
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ 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, KueryParseOptions } from '../types';
|
||||
import { KueryNode, KueryParseOptions, KueryQueryOptions } from '../types';
|
||||
|
||||
import { parse as parseKuery } from '../grammar';
|
||||
import { IndexPatternBase } from '../..';
|
||||
|
@ -62,18 +62,19 @@ export const fromKueryExpression = (
|
|||
*
|
||||
* IndexPattern isn't required, but if you pass one in, we can be more intelligent
|
||||
* about how we craft the queries (e.g. scripted fields)
|
||||
*
|
||||
*/
|
||||
export const toElasticsearchQuery = (
|
||||
node: KueryNode,
|
||||
indexPattern?: IndexPatternBase,
|
||||
config?: Record<string, any>,
|
||||
config: KueryQueryOptions = {},
|
||||
context?: Record<string, any>
|
||||
): JsonObject => {
|
||||
if (!node || !node.type || !nodeTypes[node.type]) {
|
||||
return toElasticsearchQuery(nodeTypes.function.buildNode('and', []), indexPattern);
|
||||
}
|
||||
|
||||
// TODO: the return type of this function might be incorrect and it works only because of this casting
|
||||
const nodeType = (nodeTypes[node.type] as unknown) as any;
|
||||
|
||||
return nodeType.toElasticsearchQuery(node, indexPattern, config, context);
|
||||
};
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { IndexPatternFieldBase, IndexPatternBase, KueryNode } from '../..';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { IndexPatternFieldBase, IndexPatternBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import * as literal from '../node_types/literal';
|
||||
|
||||
export function buildNodeParams(fieldName: string) {
|
||||
|
@ -18,9 +19,9 @@ export function buildNodeParams(fieldName: string) {
|
|||
export function toElasticsearchQuery(
|
||||
node: KueryNode,
|
||||
indexPattern?: IndexPatternBase,
|
||||
config: Record<string, any> = {},
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
) {
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const {
|
||||
arguments: [fieldNameArg],
|
||||
} = node;
|
||||
|
@ -28,7 +29,7 @@ export function toElasticsearchQuery(
|
|||
...fieldNameArg,
|
||||
value: context?.nested ? `${context.nested.path}.${fieldNameArg.value}` : fieldNameArg.value,
|
||||
};
|
||||
const fieldName = literal.toElasticsearchQuery(fullFieldNameArg);
|
||||
const fieldName = literal.toElasticsearchQuery(fullFieldNameArg) as string;
|
||||
const field = indexPattern?.fields?.find((fld: IndexPatternFieldBase) => fld.name === fieldName);
|
||||
|
||||
if (field?.scripted) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import { fields } from '../../filters/stubs';
|
|||
import { IndexPatternBase } from '../..';
|
||||
|
||||
import * as geoBoundingBox from './geo_bounding_box';
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
|
||||
jest.mock('../grammar');
|
||||
|
||||
|
@ -78,8 +79,14 @@ describe('kuery functions', () => {
|
|||
const result = geoBoundingBox.toElasticsearchQuery(node, indexPattern);
|
||||
|
||||
expect(result).toHaveProperty('geo_bounding_box');
|
||||
expect(result.geo_bounding_box.geo).toHaveProperty('top_left', '73.12, -174.37');
|
||||
expect(result.geo_bounding_box.geo).toHaveProperty('bottom_right', '50.73, -135.35');
|
||||
expect((result.geo_bounding_box as JsonObject).geo).toHaveProperty(
|
||||
'top_left',
|
||||
'73.12, -174.37'
|
||||
);
|
||||
expect((result.geo_bounding_box as JsonObject).geo).toHaveProperty(
|
||||
'bottom_right',
|
||||
'50.73, -135.35'
|
||||
);
|
||||
});
|
||||
|
||||
test('should return an ES geo_bounding_box query without an index pattern', () => {
|
||||
|
@ -87,15 +94,21 @@ describe('kuery functions', () => {
|
|||
const result = geoBoundingBox.toElasticsearchQuery(node);
|
||||
|
||||
expect(result).toHaveProperty('geo_bounding_box');
|
||||
expect(result.geo_bounding_box.geo).toHaveProperty('top_left', '73.12, -174.37');
|
||||
expect(result.geo_bounding_box.geo).toHaveProperty('bottom_right', '50.73, -135.35');
|
||||
expect((result.geo_bounding_box as JsonObject).geo).toHaveProperty(
|
||||
'top_left',
|
||||
'73.12, -174.37'
|
||||
);
|
||||
expect((result.geo_bounding_box as JsonObject).geo).toHaveProperty(
|
||||
'bottom_right',
|
||||
'50.73, -135.35'
|
||||
);
|
||||
});
|
||||
|
||||
test('should use the ignore_unmapped parameter', () => {
|
||||
const node = nodeTypes.function.buildNode('geoBoundingBox', 'geo', params);
|
||||
const result = geoBoundingBox.toElasticsearchQuery(node, indexPattern);
|
||||
|
||||
expect(result.geo_bounding_box.ignore_unmapped).toBe(true);
|
||||
expect(result.geo_bounding_box!.ignore_unmapped).toBe(true);
|
||||
});
|
||||
|
||||
test('should throw an error for scripted fields', () => {
|
||||
|
@ -116,7 +129,7 @@ describe('kuery functions', () => {
|
|||
);
|
||||
|
||||
expect(result).toHaveProperty('geo_bounding_box');
|
||||
expect(result.geo_bounding_box['nestedField.geo']).toBeDefined();
|
||||
expect((result.geo_bounding_box as JsonObject)['nestedField.geo']).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,9 +7,10 @@
|
|||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { nodeTypes } from '../node_types';
|
||||
import * as ast from '../ast';
|
||||
import { IndexPatternBase, KueryNode, LatLon } from '../..';
|
||||
import { IndexPatternBase, KueryNode, KueryQueryOptions, LatLon } from '../..';
|
||||
|
||||
export function buildNodeParams(fieldName: string, params: any) {
|
||||
params = _.pick(params, 'topLeft', 'bottomRight');
|
||||
|
@ -27,9 +28,9 @@ export function buildNodeParams(fieldName: string, params: any) {
|
|||
export function toElasticsearchQuery(
|
||||
node: KueryNode,
|
||||
indexPattern?: IndexPatternBase,
|
||||
config: Record<string, any> = {},
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
) {
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const [fieldNameArg, ...args] = node.arguments;
|
||||
const fullFieldNameArg = {
|
||||
...fieldNameArg,
|
||||
|
|
|
@ -79,9 +79,9 @@ describe('kuery functions', () => {
|
|||
const result = geoPolygon.toElasticsearchQuery(node, indexPattern);
|
||||
|
||||
expect(result).toHaveProperty('geo_polygon');
|
||||
expect(result.geo_polygon.geo).toHaveProperty('points');
|
||||
expect((result.geo_polygon as any).geo).toHaveProperty('points');
|
||||
|
||||
(result.geo_polygon.geo as any).points.forEach((point: any, index: number) => {
|
||||
(result.geo_polygon as any).geo.points.forEach((point: any, index: number) => {
|
||||
const expectedLatLon = `${points[index].lat}, ${points[index].lon}`;
|
||||
|
||||
expect(point).toBe(expectedLatLon);
|
||||
|
@ -93,9 +93,9 @@ describe('kuery functions', () => {
|
|||
const result = geoPolygon.toElasticsearchQuery(node);
|
||||
|
||||
expect(result).toHaveProperty('geo_polygon');
|
||||
expect(result.geo_polygon.geo).toHaveProperty('points');
|
||||
expect((result.geo_polygon as any).geo).toHaveProperty('points');
|
||||
|
||||
(result.geo_polygon.geo as any).points.forEach((point: any, index: number) => {
|
||||
(result.geo_polygon as any).geo.points.forEach((point: any, index: number) => {
|
||||
const expectedLatLon = `${points[index].lat}, ${points[index].lon}`;
|
||||
|
||||
expect(point).toBe(expectedLatLon);
|
||||
|
@ -106,7 +106,7 @@ describe('kuery functions', () => {
|
|||
const node = nodeTypes.function.buildNode('geoPolygon', 'geo', points);
|
||||
const result = geoPolygon.toElasticsearchQuery(node, indexPattern);
|
||||
|
||||
expect(result.geo_polygon.ignore_unmapped).toBe(true);
|
||||
expect((result.geo_polygon as any).ignore_unmapped).toBe(true);
|
||||
});
|
||||
|
||||
test('should throw an error for scripted fields', () => {
|
||||
|
@ -126,7 +126,7 @@ describe('kuery functions', () => {
|
|||
);
|
||||
|
||||
expect(result).toHaveProperty('geo_polygon');
|
||||
expect(result.geo_polygon['nestedField.geo']).toBeDefined();
|
||||
expect((result.geo_polygon as any)['nestedField.geo']).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,9 +6,10 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { nodeTypes } from '../node_types';
|
||||
import * as ast from '../ast';
|
||||
import { IndexPatternBase, KueryNode, LatLon } from '../..';
|
||||
import { IndexPatternBase, KueryNode, KueryQueryOptions, LatLon } from '../..';
|
||||
import { LiteralTypeBuildNode } from '../node_types/types';
|
||||
|
||||
export function buildNodeParams(fieldName: string, points: LatLon[]) {
|
||||
|
@ -26,9 +27,9 @@ export function buildNodeParams(fieldName: string, points: LatLon[]) {
|
|||
export function toElasticsearchQuery(
|
||||
node: KueryNode,
|
||||
indexPattern?: IndexPatternBase,
|
||||
config: Record<string, any> = {},
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
) {
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const [fieldNameArg, ...points] = node.arguments;
|
||||
const fullFieldNameArg = {
|
||||
...fieldNameArg,
|
||||
|
|
|
@ -11,6 +11,7 @@ import { fields } from '../../filters/stubs';
|
|||
|
||||
import * as is from './is';
|
||||
import { IndexPatternBase } from '../..';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
|
||||
jest.mock('../grammar');
|
||||
|
||||
|
@ -125,7 +126,9 @@ describe('kuery functions', () => {
|
|||
const result = is.toElasticsearchQuery(node, indexPattern);
|
||||
|
||||
expect(result).toHaveProperty('bool');
|
||||
expect(result.bool!.should!.length).toBe(indexPattern.fields.length);
|
||||
expect((result.bool!.should! as estypes.QueryDslQueryContainer[]).length).toBe(
|
||||
indexPattern.fields.length
|
||||
);
|
||||
});
|
||||
|
||||
test('should return an ES exists query when value is "*"', () => {
|
||||
|
@ -204,7 +207,9 @@ describe('kuery functions', () => {
|
|||
const node = nodeTypes.function.buildNode('is', 'script string', 'foo');
|
||||
const result = is.toElasticsearchQuery(node, indexPattern);
|
||||
|
||||
expect(result.bool!.should![0]).toHaveProperty('script');
|
||||
expect((result.bool!.should as estypes.QueryDslQueryContainer[])[0]).toHaveProperty(
|
||||
'script'
|
||||
);
|
||||
});
|
||||
|
||||
test('should support date fields without a dateFormat provided', () => {
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
*/
|
||||
|
||||
import { get, isUndefined } from 'lodash';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { getPhraseScript } from '../../filters';
|
||||
import { getFields } from './utils/get_fields';
|
||||
import { getTimeZoneFromSettings } from '../../utils';
|
||||
import { getFullFieldNameNode } from './utils/get_full_field_name_node';
|
||||
import { IndexPatternBase, KueryNode, IndexPatternFieldBase } from '../..';
|
||||
import { IndexPatternBase, KueryNode, IndexPatternFieldBase, KueryQueryOptions } from '../..';
|
||||
|
||||
import * as ast from '../ast';
|
||||
|
||||
|
@ -40,9 +41,9 @@ export function buildNodeParams(fieldName: string, value: any, isPhrase: boolean
|
|||
export function toElasticsearchQuery(
|
||||
node: KueryNode,
|
||||
indexPattern?: IndexPatternBase,
|
||||
config: Record<string, any> = {},
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
) {
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const {
|
||||
arguments: [fieldNameArg, valueArg, isPhraseArg],
|
||||
} = node;
|
||||
|
@ -75,7 +76,7 @@ export function toElasticsearchQuery(
|
|||
return {
|
||||
multi_match: {
|
||||
type,
|
||||
query: value,
|
||||
query: (value as unknown) as string,
|
||||
lenient: true,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -48,8 +48,8 @@ describe('kuery functions', () => {
|
|||
expect(result).toHaveProperty('nested');
|
||||
expect(Object.keys(result).length).toBe(1);
|
||||
|
||||
expect(result.nested.path).toBe('nestedField');
|
||||
expect(result.nested.score_mode).toBe('none');
|
||||
expect(result.nested?.path).toBe('nestedField');
|
||||
expect(result.nested?.score_mode).toBe('none');
|
||||
});
|
||||
|
||||
test('should pass the nested path to subqueries so the full field name can be used', () => {
|
||||
|
@ -59,7 +59,7 @@ describe('kuery functions', () => {
|
|||
nodeTypes.function.buildNode('is', 'nestedField.child', 'foo')
|
||||
);
|
||||
|
||||
expect(result.nested.query).toEqual(expectedSubQuery);
|
||||
expect(result.nested!.query).toEqual(expectedSubQuery);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,9 +6,10 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import * as ast from '../ast';
|
||||
import * as literal from '../node_types/literal';
|
||||
import { IndexPatternBase, KueryNode } from '../..';
|
||||
import { IndexPatternBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
|
||||
export function buildNodeParams(path: any, child: any) {
|
||||
const pathNode =
|
||||
|
@ -21,11 +22,11 @@ export function buildNodeParams(path: any, child: any) {
|
|||
export function toElasticsearchQuery(
|
||||
node: KueryNode,
|
||||
indexPattern?: IndexPatternBase,
|
||||
config: Record<string, any> = {},
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
) {
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const [path, child] = node.arguments;
|
||||
const stringPath = ast.toElasticsearchQuery(path);
|
||||
const stringPath = (ast.toElasticsearchQuery(path) as unknown) as string;
|
||||
const fullPath = context?.nested?.path ? `${context.nested.path}.${stringPath}` : stringPath;
|
||||
|
||||
return {
|
||||
|
@ -34,7 +35,7 @@ export function toElasticsearchQuery(
|
|||
query: ast.toElasticsearchQuery(child, indexPattern, config, {
|
||||
...context,
|
||||
nested: { path: fullPath },
|
||||
}),
|
||||
}) as estypes.QueryDslQueryContainer,
|
||||
score_mode: 'none',
|
||||
},
|
||||
};
|
||||
|
|
|
@ -46,9 +46,9 @@ describe('kuery functions', () => {
|
|||
expect(Object.keys(result).length).toBe(1);
|
||||
|
||||
expect(result.bool).toHaveProperty('must_not');
|
||||
expect(Object.keys(result.bool).length).toBe(1);
|
||||
expect(Object.keys(result.bool!).length).toBe(1);
|
||||
|
||||
expect(result.bool.must_not).toEqual(ast.toElasticsearchQuery(childNode, indexPattern));
|
||||
expect(result.bool!.must_not).toEqual(ast.toElasticsearchQuery(childNode, indexPattern));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import * as ast from '../ast';
|
||||
import { IndexPatternBase, KueryNode } from '../..';
|
||||
import { IndexPatternBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
|
||||
export function buildNodeParams(child: KueryNode) {
|
||||
return {
|
||||
|
@ -18,14 +19,19 @@ export function buildNodeParams(child: KueryNode) {
|
|||
export function toElasticsearchQuery(
|
||||
node: KueryNode,
|
||||
indexPattern?: IndexPatternBase,
|
||||
config: Record<string, any> = {},
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
) {
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const [argument] = node.arguments;
|
||||
|
||||
return {
|
||||
bool: {
|
||||
must_not: ast.toElasticsearchQuery(argument, indexPattern, config, context),
|
||||
must_not: ast.toElasticsearchQuery(
|
||||
argument,
|
||||
indexPattern,
|
||||
config,
|
||||
context
|
||||
) as estypes.QueryDslQueryContainer,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ describe('kuery functions', () => {
|
|||
expect(result).toHaveProperty('bool');
|
||||
expect(Object.keys(result).length).toBe(1);
|
||||
expect(result.bool).toHaveProperty('should');
|
||||
expect(result.bool.should).toEqual(
|
||||
expect(result.bool!.should).toEqual(
|
||||
[childNode1, childNode2].map((childNode) =>
|
||||
ast.toElasticsearchQuery(childNode, indexPattern)
|
||||
)
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import * as ast from '../ast';
|
||||
import { IndexPatternBase, KueryNode } from '../..';
|
||||
import { IndexPatternBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
|
||||
export function buildNodeParams(children: KueryNode[]) {
|
||||
return {
|
||||
|
@ -18,9 +19,9 @@ export function buildNodeParams(children: KueryNode[]) {
|
|||
export function toElasticsearchQuery(
|
||||
node: KueryNode,
|
||||
indexPattern?: IndexPatternBase,
|
||||
config: Record<string, any> = {},
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
) {
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const children = node.arguments || [];
|
||||
|
||||
return {
|
||||
|
|
|
@ -13,6 +13,7 @@ import { IndexPatternBase } from '../..';
|
|||
import { RangeFilterParams } from '../../filters';
|
||||
|
||||
import * as range from './range';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
jest.mock('../grammar');
|
||||
|
||||
describe('kuery functions', () => {
|
||||
|
@ -128,7 +129,9 @@ describe('kuery functions', () => {
|
|||
const node = nodeTypes.function.buildNode('range', 'script number', { gt: 1000, lt: 8000 });
|
||||
const result = range.toElasticsearchQuery(node, indexPattern);
|
||||
|
||||
expect(result.bool.should[0]).toHaveProperty('script');
|
||||
expect((result.bool!.should as estypes.QueryDslQueryContainer[])[0]).toHaveProperty(
|
||||
'script'
|
||||
);
|
||||
});
|
||||
|
||||
test('should support date fields without a dateFormat provided', () => {
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { nodeTypes } from '../node_types';
|
||||
import * as ast from '../ast';
|
||||
import { getRangeScript, RangeFilterParams } from '../../filters';
|
||||
import { getFields } from './utils/get_fields';
|
||||
import { getTimeZoneFromSettings } from '../../utils';
|
||||
import { getFullFieldNameNode } from './utils/get_full_field_name_node';
|
||||
import { IndexPatternBase, KueryNode } from '../..';
|
||||
import { IndexPatternBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
|
||||
export function buildNodeParams(fieldName: string, params: RangeFilterParams) {
|
||||
const paramsToMap = _.pick(params, 'gt', 'lt', 'gte', 'lte', 'format');
|
||||
|
@ -34,9 +35,9 @@ export function buildNodeParams(fieldName: string, params: RangeFilterParams) {
|
|||
export function toElasticsearchQuery(
|
||||
node: KueryNode,
|
||||
indexPattern?: IndexPatternBase,
|
||||
config: Record<string, any> = {},
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
) {
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const [fieldNameArg, ...args] = node.arguments;
|
||||
const fullFieldNameArg = getFullFieldNameNode(
|
||||
fieldNameArg,
|
||||
|
|
|
@ -6,7 +6,21 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { toElasticsearchQuery as astToElasticsearchQuery } from './ast';
|
||||
|
||||
/**
|
||||
* @params {String} indexPattern
|
||||
* @params {Object} config - contains the dateFormatTZ
|
||||
*
|
||||
* IndexPattern isn't required, but if you pass one in, we can be more intelligent
|
||||
* about how we craft the queries (e.g. scripted fields)
|
||||
*/
|
||||
export const toElasticsearchQuery = (...params: Parameters<typeof astToElasticsearchQuery>) => {
|
||||
return astToElasticsearchQuery(...params) as estypes.QueryDslQueryContainer;
|
||||
};
|
||||
|
||||
export { KQLSyntaxError } from './kuery_syntax_error';
|
||||
export { nodeTypes, nodeBuilder } from './node_types';
|
||||
export { fromKueryExpression, toElasticsearchQuery } from './ast';
|
||||
export { fromKueryExpression } from './ast';
|
||||
export { DslQuery, KueryNode, KueryQueryOptions } from './types';
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import _ from 'lodash';
|
||||
|
||||
import { functions } from '../functions';
|
||||
import { IndexPatternBase, KueryNode } from '../..';
|
||||
import { IndexPatternBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import { FunctionName, FunctionTypeBuildNode } from './types';
|
||||
|
||||
export function buildNode(functionName: FunctionName, ...args: any[]) {
|
||||
|
@ -46,7 +46,7 @@ export function buildNodeWithArgumentNodes(
|
|||
export function toElasticsearchQuery(
|
||||
node: KueryNode,
|
||||
indexPattern?: IndexPatternBase,
|
||||
config?: Record<string, any>,
|
||||
config?: KueryQueryOptions,
|
||||
context?: Record<string, any>
|
||||
) {
|
||||
const kueryFunction = functions[node.function as FunctionName];
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
import { JsonValue } from '@kbn/utility-types';
|
||||
import { KueryNode } from '..';
|
||||
import { KueryNode, KueryQueryOptions } from '..';
|
||||
import { IndexPatternBase } from '../..';
|
||||
|
||||
export type FunctionName =
|
||||
|
@ -31,7 +31,7 @@ interface FunctionType {
|
|||
toElasticsearchQuery: (
|
||||
node: any,
|
||||
indexPattern?: IndexPatternBase,
|
||||
config?: Record<string, any>,
|
||||
config?: KueryQueryOptions,
|
||||
context?: Record<string, any>
|
||||
) => JsonValue;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { SerializableRecord } from '@kbn/utility-types';
|
||||
import { NodeTypes } from './node_types';
|
||||
|
||||
/** @public */
|
||||
|
@ -22,9 +23,7 @@ export type DslQuery = estypes.QueryDslQueryContainer;
|
|||
|
||||
/** @internal */
|
||||
export interface KueryParseOptions {
|
||||
helpers: {
|
||||
[key: string]: any;
|
||||
};
|
||||
helpers: SerializableRecord;
|
||||
startRule: string;
|
||||
allowLeadingWildcards: boolean;
|
||||
cursorSymbol?: string;
|
||||
|
|
|
@ -22,4 +22,5 @@ export const phrasesFilter: PhrasesFilter = {
|
|||
$state: {
|
||||
store: FilterStateStore.APP_STATE,
|
||||
},
|
||||
query: {},
|
||||
};
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
import { CoreSetup } from 'kibana/public';
|
||||
import { $Keys } from 'utility-types';
|
||||
import { flatten, uniqBy } from 'lodash';
|
||||
import { fromKueryExpression } from '@kbn/es-query';
|
||||
import { setupGetFieldSuggestions } from './field';
|
||||
import { setupGetValueSuggestions } from './value';
|
||||
import { setupGetOperatorSuggestions } from './operator';
|
||||
import { setupGetConjunctionSuggestions } from './conjunction';
|
||||
import {
|
||||
esKuery,
|
||||
QuerySuggestion,
|
||||
QuerySuggestionGetFnArgs,
|
||||
QuerySuggestionGetFn,
|
||||
|
@ -43,7 +43,7 @@ export const setupKqlQuerySuggestionProvider = (
|
|||
querySuggestionsArgs: QuerySuggestionGetFnArgs
|
||||
): Array<Promise<QuerySuggestion[]>> | [] => {
|
||||
try {
|
||||
const cursorNode = esKuery.fromKueryExpression(cursoredQuery, {
|
||||
const cursorNode = fromKueryExpression(cursoredQuery, {
|
||||
cursorSymbol,
|
||||
parseCursor: true,
|
||||
});
|
||||
|
|
|
@ -792,7 +792,7 @@ export const esFilters: {
|
|||
export const esKuery: {
|
||||
nodeTypes: import("@kbn/es-query/target_types/kuery/node_types").NodeTypes;
|
||||
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;
|
||||
toElasticsearchQuery: (node: import("@kbn/es-query").KueryNode, indexPattern?: import("@kbn/es-query").IndexPatternBase | undefined, config?: import("@kbn/es-query").KueryQueryOptions | undefined, context?: Record<string, any> | undefined) => import("@elastic/elasticsearch/api/types").QueryDslQueryContainer;
|
||||
};
|
||||
|
||||
// Warning: (ae-missing-release-tag) "esQuery" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
|
|
|
@ -11,21 +11,21 @@ import { FilterManager } from '../filter_manager';
|
|||
|
||||
import {
|
||||
Filter,
|
||||
IFieldType,
|
||||
IIndexPattern,
|
||||
IndexPatternFieldBase,
|
||||
IndexPatternBase,
|
||||
isExistsFilter,
|
||||
buildExistsFilter,
|
||||
PhraseFilter,
|
||||
isPhraseFilter,
|
||||
RangeFilter,
|
||||
isRangeFilter,
|
||||
} from '../../../../common';
|
||||
} from '@kbn/es-query';
|
||||
|
||||
const INDEX_NAME = 'my-index';
|
||||
const EXISTS_FIELD_NAME = '_exists_';
|
||||
const FIELD = {
|
||||
name: 'my-field',
|
||||
} as IFieldType;
|
||||
} as IndexPatternFieldBase;
|
||||
const PHRASE_VALUE = 'my-value';
|
||||
|
||||
describe('Generate filters', () => {
|
||||
|
@ -70,7 +70,7 @@ describe('Generate filters', () => {
|
|||
});
|
||||
|
||||
it('should update and re-enable EXISTING exists filter', () => {
|
||||
const filter = buildExistsFilter(FIELD, { id: INDEX_NAME } as IIndexPattern);
|
||||
const filter = buildExistsFilter(FIELD, { id: INDEX_NAME } as IndexPatternBase);
|
||||
filter.meta.disabled = true;
|
||||
filtersArray.push(filter);
|
||||
|
||||
|
@ -110,7 +110,7 @@ describe('Generate filters', () => {
|
|||
{
|
||||
name: 'my-field',
|
||||
type: 'ip_range',
|
||||
} as IFieldType,
|
||||
} as IndexPatternFieldBase,
|
||||
{
|
||||
gt: '192.168.0.0',
|
||||
lte: '192.168.255.255',
|
||||
|
@ -136,7 +136,7 @@ describe('Generate filters', () => {
|
|||
{
|
||||
name: 'my-field',
|
||||
type: 'number_range',
|
||||
} as IFieldType,
|
||||
} as IndexPatternFieldBase,
|
||||
10000,
|
||||
'+',
|
||||
INDEX_NAME
|
||||
|
|
|
@ -125,7 +125,7 @@ export const esFilters: {
|
|||
export const esKuery: {
|
||||
nodeTypes: import("@kbn/es-query/target_types/kuery/node_types").NodeTypes;
|
||||
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;
|
||||
toElasticsearchQuery: (node: import("@kbn/es-query").KueryNode, indexPattern?: import("@kbn/es-query").IndexPatternBase | undefined, config?: import("@kbn/es-query").KueryQueryOptions | undefined, context?: Record<string, any> | undefined) => import("@elastic/elasticsearch/api/types").QueryDslQueryContainer;
|
||||
};
|
||||
|
||||
// Warning: (ae-missing-release-tag) "esQuery" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
|
|
|
@ -9,6 +9,7 @@ import Boom from '@hapi/boom';
|
|||
import { map, mapValues, fromPairs, has } from 'lodash';
|
||||
import { KibanaRequest } from 'src/core/server';
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
import { KueryNode } from '@kbn/es-query';
|
||||
import { ALERTS_FEATURE_ID, RuleTypeRegistry } from '../types';
|
||||
import { SecurityPluginSetup } from '../../../security/server';
|
||||
import { RegistryRuleType } from '../rule_type_registry';
|
||||
|
@ -20,7 +21,6 @@ import {
|
|||
asFiltersBySpaceId,
|
||||
AlertingAuthorizationFilterOpts,
|
||||
} from './alerting_authorization_kuery';
|
||||
import { KueryNode } from '../../../../../src/plugins/data/server';
|
||||
|
||||
export enum AlertingAuthorizationEntity {
|
||||
Rule = 'rule',
|
||||
|
@ -312,7 +312,11 @@ export class AlertingAuthorization {
|
|||
|
||||
const authorizedEntries: Map<string, Set<string>> = new Map();
|
||||
return {
|
||||
filter: asFiltersByRuleTypeAndConsumer(authorizedRuleTypes, filterOpts, this.spaceId),
|
||||
filter: asFiltersByRuleTypeAndConsumer(
|
||||
authorizedRuleTypes,
|
||||
filterOpts,
|
||||
this.spaceId
|
||||
) as JsonObject,
|
||||
ensureRuleTypeIsAuthorized: (ruleTypeId: string, consumer: string, authType: string) => {
|
||||
if (!authorizedRuleTypeIdsToConsumers.has(`${ruleTypeId}/${consumer}/${authType}`)) {
|
||||
throw Boom.forbidden(
|
||||
|
@ -356,7 +360,7 @@ export class AlertingAuthorization {
|
|||
}
|
||||
|
||||
return {
|
||||
filter: asFiltersBySpaceId(filterOpts, this.spaceId),
|
||||
filter: asFiltersBySpaceId(filterOpts, this.spaceId) as JsonObject,
|
||||
ensureRuleTypeIsAuthorized: (ruleTypeId: string, consumer: string, authType: string) => {},
|
||||
logSuccessfulAuthorization: () => {},
|
||||
};
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
*/
|
||||
|
||||
import { remove } from 'lodash';
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
import { EsQueryConfig, nodeBuilder, toElasticsearchQuery, KueryNode } from '@kbn/es-query';
|
||||
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { RegistryAlertTypeWithAuth } from './alerting_authorization';
|
||||
|
||||
export enum AlertingAuthorizationFilterType {
|
||||
|
@ -38,7 +38,7 @@ export function asFiltersByRuleTypeAndConsumer(
|
|||
ruleTypes: Set<RegistryAlertTypeWithAuth>,
|
||||
opts: AlertingAuthorizationFilterOpts,
|
||||
spaceId: string | undefined
|
||||
): KueryNode | JsonObject {
|
||||
): KueryNode | estypes.QueryDslQueryContainer {
|
||||
const kueryNode = nodeBuilder.or(
|
||||
Array.from(ruleTypes).reduce<KueryNode[]>((filters, { id, authorizedConsumers }) => {
|
||||
ensureFieldIsSafeForQuery('ruleTypeId', id);
|
||||
|
@ -75,7 +75,7 @@ export function asFiltersByRuleTypeAndConsumer(
|
|||
export function asFiltersBySpaceId(
|
||||
opts: AlertingAuthorizationFilterOpts,
|
||||
spaceId: string | undefined
|
||||
): KueryNode | JsonObject | undefined {
|
||||
): KueryNode | estypes.QueryDslQueryContainer | undefined {
|
||||
if (opts.fieldNames.spaceIds != null && spaceId != null) {
|
||||
const kueryNode = nodeBuilder.is(opts.fieldNames.spaceIds, spaceId);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
import { notFound } from '@hapi/boom';
|
||||
import { debounce } from 'lodash';
|
||||
import { nodeBuilder, fromKueryExpression } from '@kbn/es-query';
|
||||
import {
|
||||
CoreSetup,
|
||||
CoreStart,
|
||||
|
@ -20,12 +21,10 @@ import {
|
|||
import {
|
||||
IKibanaSearchRequest,
|
||||
ISearchOptions,
|
||||
nodeBuilder,
|
||||
ENHANCED_ES_SEARCH_STRATEGY,
|
||||
SEARCH_SESSION_TYPE,
|
||||
} from '../../../../../../src/plugins/data/common';
|
||||
import {
|
||||
esKuery,
|
||||
ISearchSessionService,
|
||||
NoSearchIdInSessionError,
|
||||
} from '../../../../../../src/plugins/data/server';
|
||||
|
@ -375,9 +374,7 @@ export class SearchSessionService
|
|||
nodeBuilder.is(`${SEARCH_SESSION_TYPE}.attributes.username`, `${user.username}`),
|
||||
];
|
||||
const filterKueryNode =
|
||||
typeof options.filter === 'string'
|
||||
? esKuery.fromKueryExpression(options.filter)
|
||||
: options.filter;
|
||||
typeof options.filter === 'string' ? fromKueryExpression(options.filter) : options.filter;
|
||||
const filter = nodeBuilder.and(userFilters.concat(filterKueryNode ?? []));
|
||||
return savedObjectsClient.find<SearchSessionSavedObjectAttributes>({
|
||||
...options,
|
||||
|
|
|
@ -8,12 +8,8 @@
|
|||
import React, { FC, useEffect, useState } from 'react';
|
||||
import { EuiCode, EuiFlexItem, EuiFlexGroup, EuiInputPopover } from '@elastic/eui';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import {
|
||||
esKuery,
|
||||
esQuery,
|
||||
Query,
|
||||
QueryStringInput,
|
||||
} from '../../../../../../../../src/plugins/data/public';
|
||||
import { Query, fromKueryExpression, luceneStringToDsl, toElasticsearchQuery } from '@kbn/es-query';
|
||||
import { QueryStringInput } from '../../../../../../../../src/plugins/data/public';
|
||||
import { ShardSizeFilter } from './shard_size_select';
|
||||
import { DataVisualizerFieldNamesFilter } from './field_name_filter';
|
||||
import { DatavisualizerFieldTypeFilter } from './field_type_filter';
|
||||
|
@ -83,12 +79,9 @@ export const SearchPanel: FC<Props> = ({
|
|||
let filterQuery;
|
||||
try {
|
||||
if (query.language === SEARCH_QUERY_LANGUAGE.KUERY) {
|
||||
filterQuery = esKuery.toElasticsearchQuery(
|
||||
esKuery.fromKueryExpression(query.query),
|
||||
indexPattern
|
||||
);
|
||||
filterQuery = toElasticsearchQuery(fromKueryExpression(query.query), indexPattern);
|
||||
} else if (query.language === SEARCH_QUERY_LANGUAGE.LUCENE) {
|
||||
filterQuery = esQuery.luceneStringToDsl(query.query);
|
||||
filterQuery = luceneStringToDsl(query.query);
|
||||
} else {
|
||||
filterQuery = {};
|
||||
}
|
||||
|
|
|
@ -7,10 +7,19 @@
|
|||
|
||||
import { cloneDeep } from 'lodash';
|
||||
import { IUiSettingsClient } from 'kibana/public';
|
||||
import {
|
||||
buildEsQuery,
|
||||
buildQueryFromFilters,
|
||||
decorateQuery,
|
||||
fromKueryExpression,
|
||||
luceneStringToDsl,
|
||||
toElasticsearchQuery,
|
||||
} from '@kbn/es-query';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { SavedSearchSavedObject } from '../../../../common/types';
|
||||
import { IndexPattern } from '../../../../../../../src/plugins/data/common/index_patterns/index_patterns';
|
||||
import { SEARCH_QUERY_LANGUAGE, SearchQueryLanguage } from '../types/combined_query';
|
||||
import { esKuery, esQuery, Query } from '../../../../../../../src/plugins/data/public';
|
||||
import { getEsQueryConfig, Query } from '../../../../../../../src/plugins/data/public';
|
||||
|
||||
export function getQueryFromSavedSearch(savedSearch: SavedSearchSavedObject) {
|
||||
const search = savedSearch.attributes.kibanaSavedObjectMeta as { searchSourceJSON: string };
|
||||
|
@ -37,11 +46,11 @@ export function extractSearchData(
|
|||
const qryString = extractedQuery.query;
|
||||
let qry;
|
||||
if (queryLanguage === SEARCH_QUERY_LANGUAGE.KUERY) {
|
||||
const ast = esKuery.fromKueryExpression(qryString);
|
||||
qry = esKuery.toElasticsearchQuery(ast, currentIndexPattern);
|
||||
const ast = fromKueryExpression(qryString);
|
||||
qry = toElasticsearchQuery(ast, currentIndexPattern);
|
||||
} else {
|
||||
qry = esQuery.luceneStringToDsl(qryString);
|
||||
esQuery.decorateQuery(qry, queryStringOptions);
|
||||
qry = luceneStringToDsl(qryString);
|
||||
decorateQuery(qry, queryStringOptions);
|
||||
}
|
||||
return {
|
||||
searchQuery: qry,
|
||||
|
@ -78,7 +87,7 @@ export function createSearchItems(
|
|||
language: 'lucene',
|
||||
};
|
||||
|
||||
let combinedQuery: any = getDefaultDatafeedQuery();
|
||||
let combinedQuery: estypes.QueryDslQueryContainer = getDefaultDatafeedQuery();
|
||||
if (savedSearch !== null) {
|
||||
const data = getQueryFromSavedSearch(savedSearch);
|
||||
|
||||
|
@ -88,18 +97,22 @@ export function createSearchItems(
|
|||
const filters = Array.isArray(filter) ? filter : [];
|
||||
|
||||
if (query.language === SEARCH_QUERY_LANGUAGE.KUERY) {
|
||||
const ast = esKuery.fromKueryExpression(query.query);
|
||||
const ast = fromKueryExpression(query.query);
|
||||
if (query.query !== '') {
|
||||
combinedQuery = esKuery.toElasticsearchQuery(ast, indexPattern);
|
||||
combinedQuery = toElasticsearchQuery(ast, indexPattern);
|
||||
}
|
||||
const filterQuery = esQuery.buildQueryFromFilters(filters, indexPattern);
|
||||
const filterQuery = buildQueryFromFilters(filters, indexPattern);
|
||||
|
||||
if (Array.isArray(combinedQuery.bool.filter) === false) {
|
||||
if (!combinedQuery.bool) {
|
||||
throw new Error('Missing bool on query');
|
||||
}
|
||||
|
||||
if (!Array.isArray(combinedQuery.bool.filter)) {
|
||||
combinedQuery.bool.filter =
|
||||
combinedQuery.bool.filter === undefined ? [] : [combinedQuery.bool.filter];
|
||||
}
|
||||
|
||||
if (Array.isArray(combinedQuery.bool.must_not) === false) {
|
||||
if (!Array.isArray(combinedQuery.bool.must_not)) {
|
||||
combinedQuery.bool.must_not =
|
||||
combinedQuery.bool.must_not === undefined ? [] : [combinedQuery.bool.must_not];
|
||||
}
|
||||
|
@ -107,8 +120,8 @@ export function createSearchItems(
|
|||
combinedQuery.bool.filter = [...combinedQuery.bool.filter, ...filterQuery.filter];
|
||||
combinedQuery.bool.must_not = [...combinedQuery.bool.must_not, ...filterQuery.must_not];
|
||||
} else {
|
||||
const esQueryConfigs = esQuery.getEsQueryConfig(kibanaConfig);
|
||||
combinedQuery = esQuery.buildEsQuery(indexPattern, [query], filters, esQueryConfigs);
|
||||
const esQueryConfigs = getEsQueryConfig(kibanaConfig);
|
||||
combinedQuery = buildEsQuery(indexPattern, [query], filters, esQueryConfigs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ import type { PublicMethodsOf } from '@kbn/utility-types';
|
|||
import { Logger, ElasticsearchClient } from 'src/core/server';
|
||||
import util from 'util';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
|
||||
import { IEvent, IValidatedEvent, SAVED_OBJECT_REL_PRIMARY } from '../types';
|
||||
import { FindOptionsType } from '../event_log_client';
|
||||
import { esKuery } from '../../../../../src/plugins/data/server';
|
||||
|
||||
export const EVENT_BUFFER_TIME = 1000; // milliseconds
|
||||
export const EVENT_BUFFER_LENGTH = 100;
|
||||
|
@ -228,11 +228,9 @@ export class ClusterClientAdapter<TDoc extends { body: AliasAny; index: string }
|
|||
const namespaceQuery = namespace === undefined ? defaultNamespaceQuery : namedNamespaceQuery;
|
||||
|
||||
const esClient = await this.elasticsearchClientPromise;
|
||||
let dslFilterQuery;
|
||||
let dslFilterQuery: estypes.QueryDslBoolQuery['filter'];
|
||||
try {
|
||||
dslFilterQuery = filter
|
||||
? esKuery.toElasticsearchQuery(esKuery.fromKueryExpression(filter))
|
||||
: [];
|
||||
dslFilterQuery = filter ? toElasticsearchQuery(fromKueryExpression(filter)) : [];
|
||||
} catch (err) {
|
||||
this.debug(`Invalid kuery syntax for the filter (${filter}) error:`, {
|
||||
message: err.message,
|
||||
|
|
|
@ -7,8 +7,10 @@
|
|||
|
||||
import React, { useState, useEffect, useMemo } from 'react';
|
||||
|
||||
import { fromKueryExpression } from '@kbn/es-query';
|
||||
|
||||
import type { IFieldType } from '../../../../../../../src/plugins/data/public';
|
||||
import { QueryStringInput, esKuery } from '../../../../../../../src/plugins/data/public';
|
||||
import { QueryStringInput } from '../../../../../../../src/plugins/data/public';
|
||||
import { useStartServices } from '../hooks';
|
||||
import { INDEX_NAME, AGENT_SAVED_OBJECT_TYPE } from '../constants';
|
||||
|
||||
|
@ -38,7 +40,7 @@ export const SearchBar: React.FunctionComponent<Props> = ({
|
|||
}
|
||||
|
||||
try {
|
||||
esKuery.fromKueryExpression(value);
|
||||
fromKueryExpression(value);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
|
|
@ -23,13 +23,13 @@ import {
|
|||
} from '@elastic/eui';
|
||||
import useMeasure from 'react-use/lib/useMeasure';
|
||||
import { FormattedMessage } from '@kbn/i18n/react';
|
||||
import { fromKueryExpression } from '@kbn/es-query';
|
||||
import semverGte from 'semver/functions/gte';
|
||||
import semverCoerce from 'semver/functions/coerce';
|
||||
|
||||
import { createStateContainerReactHelpers } from '../../../../../../../../../../../src/plugins/kibana_utils/public';
|
||||
import { RedirectAppLinks } from '../../../../../../../../../../../src/plugins/kibana_react/public';
|
||||
import type { TimeRange } from '../../../../../../../../../../../src/plugins/data/public';
|
||||
import { esKuery } from '../../../../../../../../../../../src/plugins/data/public';
|
||||
import { LogStream } from '../../../../../../../../../infra/public';
|
||||
import type { Agent, AgentPolicy } from '../../../../../types';
|
||||
import { useLink, useStartServices } from '../../../../../hooks';
|
||||
|
@ -171,7 +171,7 @@ export const AgentLogsUI: React.FunctionComponent<AgentLogsProps> = memo(
|
|||
// Query validation helper
|
||||
const isQueryValid = useCallback((testQuery: string) => {
|
||||
try {
|
||||
esKuery.fromKueryExpression(testQuery);
|
||||
fromKueryExpression(testQuery);
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
|
|
|
@ -9,14 +9,15 @@ import Boom from '@hapi/boom';
|
|||
import type { estypes } from '@elastic/elasticsearch';
|
||||
import type { SavedObjectsClientContract, ElasticsearchClient } from 'src/core/server';
|
||||
|
||||
import type { KueryNode } from '@kbn/es-query';
|
||||
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
|
||||
|
||||
import type { AgentSOAttributes, Agent, BulkActionResult, ListWithKuery } from '../../types';
|
||||
import { appContextService, agentPolicyService } from '../../services';
|
||||
import type { FleetServerAgent } from '../../../common';
|
||||
import { isAgentUpgradeable, SO_SEARCH_LIMIT } from '../../../common';
|
||||
import { AGENT_SAVED_OBJECT_TYPE, AGENTS_INDEX } from '../../constants';
|
||||
import { escapeSearchQueryPhrase, normalizeKuery } from '../saved_object';
|
||||
import type { KueryNode } from '../../../../../../src/plugins/data/server';
|
||||
import { esKuery } from '../../../../../../src/plugins/data/server';
|
||||
import { IngestManagerError, isESClientError, AgentNotFoundError } from '../../errors';
|
||||
|
||||
import { searchHitToAgent, agentSOAttributesToFleetServerAgentDoc } from './helpers';
|
||||
|
@ -35,9 +36,7 @@ function _joinFilters(filters: Array<string | undefined | KueryNode>): KueryNode
|
|||
return acc;
|
||||
}
|
||||
const kueryNode: KueryNode =
|
||||
typeof kuery === 'string'
|
||||
? esKuery.fromKueryExpression(removeSOAttributes(kuery))
|
||||
: kuery;
|
||||
typeof kuery === 'string' ? fromKueryExpression(removeSOAttributes(kuery)) : kuery;
|
||||
|
||||
if (!acc) {
|
||||
return kueryNode;
|
||||
|
@ -118,7 +117,7 @@ export async function getAgentsByKuery(
|
|||
}
|
||||
|
||||
const kueryNode = _joinFilters(filters);
|
||||
const body = kueryNode ? { query: esKuery.toElasticsearchQuery(kueryNode) } : {};
|
||||
const body = kueryNode ? { query: toElasticsearchQuery(kueryNode) } : {};
|
||||
const res = await esClient.search<FleetServerAgent, {}>({
|
||||
index: AGENTS_INDEX,
|
||||
from: (page - 1) * perPage,
|
||||
|
@ -175,7 +174,7 @@ export async function countInactiveAgents(
|
|||
}
|
||||
|
||||
const kueryNode = _joinFilters(filters);
|
||||
const body = kueryNode ? { query: esKuery.toElasticsearchQuery(kueryNode) } : {};
|
||||
const body = kueryNode ? { query: toElasticsearchQuery(kueryNode) } : {};
|
||||
|
||||
const res = await esClient.search({
|
||||
index: AGENTS_INDEX,
|
||||
|
|
|
@ -8,13 +8,14 @@
|
|||
import Boom from '@hapi/boom';
|
||||
import type { SavedObjectsBulkUpdateObject, SavedObjectsClientContract } from 'src/core/server';
|
||||
|
||||
import type { KueryNode } from '@kbn/es-query';
|
||||
import { fromKueryExpression } from '@kbn/es-query';
|
||||
|
||||
import { isAgentUpgradeable } from '../../../common';
|
||||
import { AGENT_SAVED_OBJECT_TYPE } from '../../constants';
|
||||
import type { AgentSOAttributes, Agent, ListWithKuery } from '../../types';
|
||||
import { escapeSearchQueryPhrase, normalizeKuery, findAllSOs } from '../saved_object';
|
||||
import { appContextService } from '../../services';
|
||||
import { esKuery } from '../../../../../../src/plugins/data/server';
|
||||
import type { KueryNode } from '../../../../../../src/plugins/data/server';
|
||||
|
||||
import { savedObjectToAgent } from './saved_objects';
|
||||
|
||||
|
@ -32,7 +33,7 @@ function _joinFilters(filters: Array<string | undefined | KueryNode>) {
|
|||
}
|
||||
const kueryNode: KueryNode =
|
||||
typeof kuery === 'string'
|
||||
? esKuery.fromKueryExpression(normalizeKuery(AGENT_SAVED_OBJECT_TYPE, kuery))
|
||||
? fromKueryExpression(normalizeKuery(AGENT_SAVED_OBJECT_TYPE, kuery))
|
||||
: kuery;
|
||||
|
||||
if (!acc) {
|
||||
|
|
|
@ -8,11 +8,12 @@
|
|||
import type { ElasticsearchClient } from 'src/core/server';
|
||||
import pMap from 'p-map';
|
||||
|
||||
import type { KueryNode } from '@kbn/es-query';
|
||||
import { fromKueryExpression } from '@kbn/es-query';
|
||||
|
||||
import { AGENT_SAVED_OBJECT_TYPE } from '../../constants';
|
||||
import type { AgentStatus } from '../../types';
|
||||
import { AgentStatusKueryHelper } from '../../../common/services';
|
||||
import { esKuery } from '../../../../../../src/plugins/data/server';
|
||||
import type { KueryNode } from '../../../../../../src/plugins/data/server';
|
||||
|
||||
import { getAgentById, getAgentsByKuery, removeSOAttributes } from './crud';
|
||||
|
||||
|
@ -32,9 +33,7 @@ function joinKuerys(...kuerys: Array<string | undefined>) {
|
|||
if (kuery === undefined) {
|
||||
return acc;
|
||||
}
|
||||
const normalizedKuery: KueryNode = esKuery.fromKueryExpression(
|
||||
removeSOAttributes(kuery || '')
|
||||
);
|
||||
const normalizedKuery: KueryNode = fromKueryExpression(removeSOAttributes(kuery || ''));
|
||||
|
||||
if (!acc) {
|
||||
return normalizedKuery;
|
||||
|
|
|
@ -11,7 +11,8 @@ import { i18n } from '@kbn/i18n';
|
|||
import { ResponseError } from '@elastic/elasticsearch/lib/errors';
|
||||
import type { SavedObjectsClientContract, ElasticsearchClient } from 'src/core/server';
|
||||
|
||||
import { esKuery } from '../../../../../../src/plugins/data/server';
|
||||
import { toElasticsearchQuery, fromKueryExpression } from '@kbn/es-query';
|
||||
|
||||
import type { ESSearchResponse as SearchResponse } from '../../../../../../src/core/types/elasticsearch';
|
||||
import type { EnrollmentAPIKey, FleetServerEnrollmentAPIKey } from '../../types';
|
||||
import { IngestManagerError } from '../../errors';
|
||||
|
@ -29,13 +30,12 @@ export async function listEnrollmentApiKeys(
|
|||
page?: number;
|
||||
perPage?: number;
|
||||
kuery?: string;
|
||||
query?: ReturnType<typeof esKuery['toElasticsearchQuery']>;
|
||||
query?: ReturnType<typeof toElasticsearchQuery>;
|
||||
showInactive?: boolean;
|
||||
}
|
||||
): Promise<{ items: EnrollmentAPIKey[]; total: any; page: any; perPage: any }> {
|
||||
const { page = 1, perPage = 20, kuery } = options;
|
||||
const query =
|
||||
options.query ?? (kuery && esKuery.toElasticsearchQuery(esKuery.fromKueryExpression(kuery)));
|
||||
const query = options.query ?? (kuery && toElasticsearchQuery(fromKueryExpression(kuery)));
|
||||
|
||||
const res = await esClient.search<SearchResponse<FleetServerEnrollmentAPIKey, {}>>({
|
||||
index: ENROLLMENT_API_KEYS_INDEX,
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
*/
|
||||
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
import { buildEsQuery } from '@kbn/es-query';
|
||||
|
||||
import { isPopulatedObject } from '../util/object_utils';
|
||||
|
||||
export function isMultiBucketAggregate(
|
||||
|
@ -26,7 +22,4 @@ export const ES_CLIENT_TOTAL_HITS_RELATION: Record<
|
|||
GTE: 'gte',
|
||||
} as const;
|
||||
|
||||
export type InfluencersFilterQuery =
|
||||
| ReturnType<typeof buildEsQuery>
|
||||
| estypes.QueryDslQueryContainer
|
||||
| JsonObject;
|
||||
export type InfluencersFilterQuery = estypes.QueryDslQueryContainer;
|
||||
|
|
|
@ -6,8 +6,14 @@
|
|||
*/
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import {
|
||||
decorateQuery,
|
||||
fromKueryExpression,
|
||||
luceneStringToDsl,
|
||||
toElasticsearchQuery,
|
||||
} from '@kbn/es-query';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { useMlContext } from '../../../../../contexts/ml';
|
||||
import { esQuery, esKuery } from '../../../../../../../../../../src/plugins/data/public';
|
||||
import { SEARCH_QUERY_LANGUAGE } from '../../../../../../../common/constants/search';
|
||||
import { getQueryFromSavedSearch } from '../../../../../util/index_utils';
|
||||
|
||||
|
@ -30,7 +36,7 @@ export function useSavedSearch() {
|
|||
const { currentSavedSearch, currentIndexPattern, kibanaConfig } = mlContext;
|
||||
|
||||
const getQueryData = () => {
|
||||
let qry;
|
||||
let qry: estypes.QueryDslQueryContainer = {};
|
||||
let qryString;
|
||||
|
||||
if (currentSavedSearch !== null) {
|
||||
|
@ -39,11 +45,11 @@ export function useSavedSearch() {
|
|||
qryString = query.query;
|
||||
|
||||
if (queryLanguage === SEARCH_QUERY_LANGUAGE.KUERY) {
|
||||
const ast = esKuery.fromKueryExpression(qryString);
|
||||
qry = esKuery.toElasticsearchQuery(ast, currentIndexPattern);
|
||||
const ast = fromKueryExpression(qryString);
|
||||
qry = toElasticsearchQuery(ast, currentIndexPattern);
|
||||
} else {
|
||||
qry = esQuery.luceneStringToDsl(qryString);
|
||||
esQuery.decorateQuery(qry, kibanaConfig.get('query:queryString:options'));
|
||||
qry = luceneStringToDsl(qryString);
|
||||
decorateQuery(qry, kibanaConfig.get('query:queryString:options'));
|
||||
}
|
||||
|
||||
setSavedSearchQuery(qry);
|
||||
|
|
|
@ -10,14 +10,11 @@ import { EuiButtonGroup, EuiCode, EuiFlexGroup, EuiFlexItem, EuiInputPopover } f
|
|||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { debounce } from 'lodash';
|
||||
import { fromKueryExpression, luceneStringToDsl, toElasticsearchQuery } from '@kbn/es-query';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import { Dictionary } from '../../../../../../../common/types/common';
|
||||
import { IIndexPattern } from '../../../../../../../../../../src/plugins/data/common/index_patterns';
|
||||
import {
|
||||
esKuery,
|
||||
esQuery,
|
||||
Query,
|
||||
QueryStringInput,
|
||||
} from '../../../../../../../../../../src/plugins/data/public';
|
||||
import { Query, QueryStringInput } from '../../../../../../../../../../src/plugins/data/public';
|
||||
|
||||
import {
|
||||
SEARCH_QUERY_LANGUAGE,
|
||||
|
@ -93,16 +90,16 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({
|
|||
*/
|
||||
useEffect(() => {
|
||||
try {
|
||||
let convertedQuery;
|
||||
let convertedQuery: estypes.QueryDslQueryContainer = {};
|
||||
switch (query.language) {
|
||||
case SEARCH_QUERY_LANGUAGE.KUERY:
|
||||
convertedQuery = esKuery.toElasticsearchQuery(
|
||||
esKuery.fromKueryExpression(query.query as string),
|
||||
convertedQuery = toElasticsearchQuery(
|
||||
fromKueryExpression(query.query as string),
|
||||
indexPattern
|
||||
);
|
||||
break;
|
||||
case SEARCH_QUERY_LANGUAGE.LUCENE:
|
||||
convertedQuery = esQuery.luceneStringToDsl(query.query as string);
|
||||
convertedQuery = luceneStringToDsl(query.query as string);
|
||||
break;
|
||||
default:
|
||||
setErrorMessage({
|
||||
|
|
|
@ -8,12 +8,8 @@
|
|||
import React, { FC, useState, useEffect } from 'react';
|
||||
import { EuiCode, EuiInputPopover } from '@elastic/eui';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import {
|
||||
Query,
|
||||
esKuery,
|
||||
esQuery,
|
||||
QueryStringInput,
|
||||
} from '../../../../../../../../src/plugins/data/public';
|
||||
import { fromKueryExpression, luceneStringToDsl, toElasticsearchQuery } from '@kbn/es-query';
|
||||
import { Query, QueryStringInput } from '../../../../../../../../src/plugins/data/public';
|
||||
import { IIndexPattern } from '../../../../../../../../src/plugins/data/common/index_patterns';
|
||||
import { SEARCH_QUERY_LANGUAGE, ErrorMessage } from '../../../../../common/constants/search';
|
||||
import { explorerService } from '../../explorer_dashboard_service';
|
||||
|
@ -32,7 +28,7 @@ export function getKqlQueryValues({
|
|||
}): { clearSettings: boolean; settings: any } {
|
||||
let influencersFilterQuery: InfluencersFilterQuery = {};
|
||||
const filteredFields: string[] = [];
|
||||
const ast = esKuery.fromKueryExpression(inputString);
|
||||
const ast = fromKueryExpression(inputString);
|
||||
const isAndOperator = ast && ast.function === 'and';
|
||||
// if ast.type == 'function' then layout of ast.arguments:
|
||||
// [{ arguments: [ { type: 'literal', value: 'AAL' } ] },{ arguments: [ { type: 'literal', value: 'AAL' } ] }]
|
||||
|
@ -50,12 +46,9 @@ export function getKqlQueryValues({
|
|||
});
|
||||
}
|
||||
if (queryLanguage === SEARCH_QUERY_LANGUAGE.KUERY) {
|
||||
influencersFilterQuery = esKuery.toElasticsearchQuery(
|
||||
esKuery.fromKueryExpression(inputString),
|
||||
indexPattern
|
||||
);
|
||||
influencersFilterQuery = toElasticsearchQuery(fromKueryExpression(inputString), indexPattern);
|
||||
} else if (queryLanguage === SEARCH_QUERY_LANGUAGE.LUCENE) {
|
||||
influencersFilterQuery = esQuery.luceneStringToDsl(inputString);
|
||||
influencersFilterQuery = luceneStringToDsl(inputString);
|
||||
}
|
||||
|
||||
const clearSettings = Boolean(
|
||||
|
|
|
@ -6,9 +6,16 @@
|
|||
*/
|
||||
|
||||
import { cloneDeep } from 'lodash';
|
||||
import {
|
||||
Query,
|
||||
fromKueryExpression,
|
||||
toElasticsearchQuery,
|
||||
buildEsQuery,
|
||||
buildQueryFromFilters,
|
||||
IndexPatternBase,
|
||||
} from '@kbn/es-query';
|
||||
import { IUiSettingsClient } from 'kibana/public';
|
||||
import { esQuery, Query, esKuery } from '../../../../../../../../src/plugins/data/public';
|
||||
import { IIndexPattern } from '../../../../../../../../src/plugins/data/common/index_patterns';
|
||||
import { getEsQueryConfig } from '../../../../../../../../src/plugins/data/public';
|
||||
import { SEARCH_QUERY_LANGUAGE } from '../../../../../common/constants/search';
|
||||
import { SavedSearchSavedObject } from '../../../../../common/types/kibana';
|
||||
import { getQueryFromSavedSearch } from '../../../util/index_utils';
|
||||
|
@ -31,7 +38,7 @@ export function getDefaultDatafeedQuery() {
|
|||
|
||||
export function createSearchItems(
|
||||
kibanaConfig: IUiSettingsClient,
|
||||
indexPattern: IIndexPattern | undefined,
|
||||
indexPattern: IndexPatternBase | undefined,
|
||||
savedSearch: SavedSearchSavedObject | null
|
||||
) {
|
||||
// query is only used by the data visualizer as it needs
|
||||
|
@ -53,11 +60,11 @@ export function createSearchItems(
|
|||
const filters = Array.isArray(filter) ? filter : [];
|
||||
|
||||
if (query.language === SEARCH_QUERY_LANGUAGE.KUERY) {
|
||||
const ast = esKuery.fromKueryExpression(query.query);
|
||||
const ast = fromKueryExpression(query.query);
|
||||
if (query.query !== '') {
|
||||
combinedQuery = esKuery.toElasticsearchQuery(ast, indexPattern);
|
||||
combinedQuery = toElasticsearchQuery(ast, indexPattern);
|
||||
}
|
||||
const filterQuery = esQuery.buildQueryFromFilters(filters, indexPattern);
|
||||
const filterQuery = buildQueryFromFilters(filters, indexPattern);
|
||||
|
||||
if (Array.isArray(combinedQuery.bool.filter) === false) {
|
||||
combinedQuery.bool.filter =
|
||||
|
@ -72,8 +79,8 @@ export function createSearchItems(
|
|||
combinedQuery.bool.filter = [...combinedQuery.bool.filter, ...filterQuery.filter];
|
||||
combinedQuery.bool.must_not = [...combinedQuery.bool.must_not, ...filterQuery.must_not];
|
||||
} else {
|
||||
const esQueryConfigs = esQuery.getEsQueryConfig(kibanaConfig);
|
||||
combinedQuery = esQuery.buildEsQuery(indexPattern, [query], filters, esQueryConfigs);
|
||||
const esQueryConfigs = getEsQueryConfig(kibanaConfig);
|
||||
combinedQuery = buildEsQuery(indexPattern, [query], filters, esQueryConfigs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,14 +5,24 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { Filter, Query } from '@kbn/es-query';
|
||||
import { esKuery, esQuery } from '../../../../../../src/plugins/data/public';
|
||||
import { estypes } from '@elastic/elasticsearch';
|
||||
import {
|
||||
Filter,
|
||||
fromKueryExpression,
|
||||
luceneStringToDsl,
|
||||
Query,
|
||||
toElasticsearchQuery,
|
||||
} from '@kbn/es-query';
|
||||
|
||||
export function processFilters(filters: Filter[], query: Query, controlledBy?: string) {
|
||||
export function processFilters(
|
||||
filters: Filter[],
|
||||
query: Query,
|
||||
controlledBy?: string
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const inputQuery =
|
||||
query.language === 'kuery'
|
||||
? esKuery.toElasticsearchQuery(esKuery.fromKueryExpression(query.query as string))
|
||||
: esQuery.luceneStringToDsl(query.query);
|
||||
? toElasticsearchQuery(fromKueryExpression(query.query as string))
|
||||
: luceneStringToDsl(query.query);
|
||||
|
||||
const must = [inputQuery];
|
||||
const mustNot = [];
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import type { estypes } from '@elastic/elasticsearch';
|
||||
import { esKuery } from '../../../../../src/plugins/data/server';
|
||||
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
|
||||
|
||||
export function rangeQuery(
|
||||
start?: number,
|
||||
|
@ -31,6 +31,6 @@ export function kqlQuery(kql: string): estypes.QueryDslQueryContainer[] {
|
|||
return [];
|
||||
}
|
||||
|
||||
const ast = esKuery.fromKueryExpression(kql);
|
||||
return [esKuery.toElasticsearchQuery(ast)];
|
||||
const ast = fromKueryExpression(kql);
|
||||
return [toElasticsearchQuery(ast)];
|
||||
}
|
||||
|
|
|
@ -7,25 +7,23 @@
|
|||
|
||||
import { isEmpty, isString, flow } from 'lodash/fp';
|
||||
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
import {
|
||||
EsQueryConfig,
|
||||
Query,
|
||||
Filter,
|
||||
esQuery,
|
||||
esKuery,
|
||||
IIndexPattern,
|
||||
} from '../../../../../../../src/plugins/data/public';
|
||||
buildEsQuery,
|
||||
toElasticsearchQuery,
|
||||
fromKueryExpression,
|
||||
IndexPatternBase,
|
||||
} from '@kbn/es-query';
|
||||
|
||||
export const convertKueryToElasticSearchQuery = (
|
||||
kueryExpression: string,
|
||||
indexPattern?: IIndexPattern
|
||||
indexPattern?: IndexPatternBase
|
||||
) => {
|
||||
try {
|
||||
return kueryExpression
|
||||
? JSON.stringify(
|
||||
esKuery.toElasticsearchQuery(esKuery.fromKueryExpression(kueryExpression), indexPattern)
|
||||
)
|
||||
? JSON.stringify(toElasticsearchQuery(fromKueryExpression(kueryExpression), indexPattern))
|
||||
: '';
|
||||
} catch (err) {
|
||||
return '';
|
||||
|
@ -34,11 +32,11 @@ export const convertKueryToElasticSearchQuery = (
|
|||
|
||||
export const convertKueryToDslFilter = (
|
||||
kueryExpression: string,
|
||||
indexPattern: IIndexPattern
|
||||
): JsonObject => {
|
||||
indexPattern: IndexPatternBase
|
||||
) => {
|
||||
try {
|
||||
return kueryExpression
|
||||
? esKuery.toElasticsearchQuery(esKuery.fromKueryExpression(kueryExpression), indexPattern)
|
||||
? toElasticsearchQuery(fromKueryExpression(kueryExpression), indexPattern)
|
||||
: {};
|
||||
} catch (err) {
|
||||
return {};
|
||||
|
@ -77,14 +75,14 @@ export const convertToBuildEsQuery = ({
|
|||
filters,
|
||||
}: {
|
||||
config: EsQueryConfig;
|
||||
indexPattern: IIndexPattern;
|
||||
indexPattern: IndexPatternBase;
|
||||
queries: Query[];
|
||||
filters: Filter[];
|
||||
}): [string, undefined] | [undefined, Error] => {
|
||||
try {
|
||||
return [
|
||||
JSON.stringify(
|
||||
esQuery.buildEsQuery(
|
||||
buildEsQuery(
|
||||
indexPattern,
|
||||
queries,
|
||||
filters.filter((f) => f.meta.disabled === false),
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { Filter } from '../../../../../../../src/plugins/data/common/es_query';
|
||||
import { ExistsFilter, Filter } from '@kbn/es-query';
|
||||
import { buildAlertsRuleIdFilter, buildThreatMatchFilter } from './default_config';
|
||||
|
||||
jest.mock('./actions');
|
||||
|
@ -38,7 +38,7 @@ describe('alerts default_config', () => {
|
|||
describe('buildThreatMatchFilter', () => {
|
||||
test('given a showOnlyThreatIndicatorAlerts=true this will return an array with a single filter', () => {
|
||||
const filters: Filter[] = buildThreatMatchFilter(true);
|
||||
const expectedFilter: Filter = {
|
||||
const expectedFilter: ExistsFilter = {
|
||||
meta: {
|
||||
alias: null,
|
||||
disabled: false,
|
||||
|
@ -47,7 +47,6 @@ describe('alerts default_config', () => {
|
|||
type: 'exists',
|
||||
value: 'exists',
|
||||
},
|
||||
// @ts-expect-error TODO: Rework parent typings to support ExistsFilter[]
|
||||
exists: {
|
||||
field: 'signal.rule.threat_mapping',
|
||||
},
|
||||
|
|
|
@ -6,12 +6,7 @@
|
|||
*/
|
||||
|
||||
import { isEmpty } from 'lodash/fp';
|
||||
import {
|
||||
Filter,
|
||||
esKuery,
|
||||
KueryNode,
|
||||
esFilters,
|
||||
} from '../../../../../../../src/plugins/data/public';
|
||||
import { Filter, FilterStateStore, KueryNode, fromKueryExpression } from '@kbn/es-query';
|
||||
import {
|
||||
DataProvider,
|
||||
DataProviderType,
|
||||
|
@ -120,7 +115,7 @@ export const replaceTemplateFieldFromQuery = (
|
|||
): string => {
|
||||
if (timelineType === TimelineType.default) {
|
||||
if (query.trim() !== '') {
|
||||
const valueToChange = findValueToChangeInQuery(esKuery.fromKueryExpression(query));
|
||||
const valueToChange = findValueToChangeInQuery(fromKueryExpression(query));
|
||||
return valueToChange.reduce((newQuery, vtc) => {
|
||||
const newValue = getStringArray(vtc.field, eventData);
|
||||
if (newValue.length) {
|
||||
|
@ -243,7 +238,7 @@ export const buildTimeRangeFilter = (from: string, to: string): Filter[] => [
|
|||
},
|
||||
},
|
||||
$state: {
|
||||
store: esFilters.FilterStateStore.APP_STATE,
|
||||
store: FilterStateStore.APP_STATE,
|
||||
},
|
||||
} as Filter,
|
||||
];
|
||||
|
|
|
@ -10,6 +10,7 @@ import { i18n } from '@kbn/i18n';
|
|||
import { EuiText } from '@elastic/eui';
|
||||
import React from 'react';
|
||||
|
||||
import { fromKueryExpression } from '@kbn/es-query';
|
||||
import {
|
||||
singleEntryThreat,
|
||||
containsInvalidItems,
|
||||
|
@ -17,7 +18,6 @@ import {
|
|||
} from '../../../../common/components/threat_match/helpers';
|
||||
import { isThreatMatchRule, isThresholdRule } from '../../../../../common/detection_engine/utils';
|
||||
import { isMlRule } from '../../../../../common/machine_learning/helpers';
|
||||
import { esKuery } from '../../../../../../../../src/plugins/data/public';
|
||||
import { FieldValueQueryBar } from '../query_bar';
|
||||
import {
|
||||
ERROR_CODE,
|
||||
|
@ -107,7 +107,7 @@ export const schema: FormSchema<DefineStepRule> = {
|
|||
|
||||
if (!isEmpty(query.query as string) && query.language === 'kuery') {
|
||||
try {
|
||||
esKuery.fromKueryExpression(query.query);
|
||||
fromKueryExpression(query.query);
|
||||
} catch (err) {
|
||||
return {
|
||||
code: 'ERR_FIELD_FORMAT',
|
||||
|
@ -465,7 +465,7 @@ export const schema: FormSchema<DefineStepRule> = {
|
|||
|
||||
if (!isEmpty(query.query as string) && query.language === 'kuery') {
|
||||
try {
|
||||
esKuery.fromKueryExpression(query.query);
|
||||
fromKueryExpression(query.query);
|
||||
} catch (err) {
|
||||
return {
|
||||
code: 'ERR_FIELD_FORMAT',
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
import { useMemo } from 'react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { convertToBuildEsQuery } from '../../../common/lib/keury';
|
||||
import { esQuery } from '../../../../../../../src/plugins/data/public';
|
||||
import { getEsQueryConfig } from '../../../../../../../src/plugins/data/public';
|
||||
import { MatrixHistogramType } from '../../../../common/search_strategy';
|
||||
import { EVENT_DATASET } from '../../../../common/cti/constants';
|
||||
import { useMatrixHistogram } from '../../../common/containers/matrix_histogram';
|
||||
|
@ -19,15 +19,12 @@ export const useRequestEventCounts = (to: string, from: string) => {
|
|||
const defaultThreatIndices = uiSettings.get<string[]>(DEFAULT_THREAT_INDEX_KEY);
|
||||
|
||||
const [filterQuery] = convertToBuildEsQuery({
|
||||
config: esQuery.getEsQueryConfig(uiSettings),
|
||||
config: getEsQueryConfig(uiSettings),
|
||||
indexPattern: {
|
||||
fields: [
|
||||
{
|
||||
name: 'event.kind',
|
||||
aggregatable: true,
|
||||
searchable: true,
|
||||
type: 'string',
|
||||
esTypes: ['keyword'],
|
||||
},
|
||||
],
|
||||
title: defaultThreatIndices.toString(),
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
*/
|
||||
|
||||
import type { estypes } from '@elastic/elasticsearch';
|
||||
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
|
||||
import { metadataCurrentIndexPattern } from '../../../../common/endpoint/constants';
|
||||
import { KibanaRequest } from '../../../../../../../src/core/server';
|
||||
import { esKuery } from '../../../../../../../src/plugins/data/server';
|
||||
import { EndpointAppContext } from '../../types';
|
||||
|
||||
export interface QueryBuilderOptions {
|
||||
|
@ -123,9 +123,7 @@ function buildQueryBody(
|
|||
};
|
||||
|
||||
if (request?.body?.filters?.kql) {
|
||||
const kqlQuery = esKuery.toElasticsearchQuery(
|
||||
esKuery.fromKueryExpression(request.body.filters.kql)
|
||||
);
|
||||
const kqlQuery = toElasticsearchQuery(fromKueryExpression(request.body.filters.kql));
|
||||
const q = [];
|
||||
if (filterUnenrolledAgents || filterStatusAgents) {
|
||||
q.push(idFilter);
|
||||
|
|
|
@ -6,20 +6,23 @@
|
|||
*/
|
||||
|
||||
import { isEmpty, isString, flow } from 'lodash/fp';
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
import { EsQueryConfig, Filter, Query } from '@kbn/es-query';
|
||||
|
||||
import { esQuery, esKuery, IIndexPattern } from '../../../../../../../src/plugins/data/public';
|
||||
import {
|
||||
buildEsQuery,
|
||||
EsQueryConfig,
|
||||
Filter,
|
||||
fromKueryExpression,
|
||||
IndexPatternBase,
|
||||
Query,
|
||||
toElasticsearchQuery,
|
||||
} from '@kbn/es-query';
|
||||
|
||||
export const convertKueryToElasticSearchQuery = (
|
||||
kueryExpression: string,
|
||||
indexPattern?: IIndexPattern
|
||||
indexPattern?: IndexPatternBase
|
||||
) => {
|
||||
try {
|
||||
return kueryExpression
|
||||
? JSON.stringify(
|
||||
esKuery.toElasticsearchQuery(esKuery.fromKueryExpression(kueryExpression), indexPattern)
|
||||
)
|
||||
? JSON.stringify(toElasticsearchQuery(fromKueryExpression(kueryExpression), indexPattern))
|
||||
: '';
|
||||
} catch (err) {
|
||||
return '';
|
||||
|
@ -28,11 +31,11 @@ export const convertKueryToElasticSearchQuery = (
|
|||
|
||||
export const convertKueryToDslFilter = (
|
||||
kueryExpression: string,
|
||||
indexPattern: IIndexPattern
|
||||
): JsonObject => {
|
||||
indexPattern: IndexPatternBase
|
||||
) => {
|
||||
try {
|
||||
return kueryExpression
|
||||
? esKuery.toElasticsearchQuery(esKuery.fromKueryExpression(kueryExpression), indexPattern)
|
||||
? toElasticsearchQuery(fromKueryExpression(kueryExpression), indexPattern)
|
||||
: {};
|
||||
} catch (err) {
|
||||
return {};
|
||||
|
@ -71,13 +74,13 @@ export const convertToBuildEsQuery = ({
|
|||
filters,
|
||||
}: {
|
||||
config: EsQueryConfig;
|
||||
indexPattern: IIndexPattern;
|
||||
indexPattern: IndexPatternBase;
|
||||
queries: Query[];
|
||||
filters: Filter[];
|
||||
}) => {
|
||||
try {
|
||||
return JSON.stringify(
|
||||
esQuery.buildEsQuery(
|
||||
buildEsQuery(
|
||||
indexPattern,
|
||||
queries,
|
||||
filters.filter((f) => f.meta.disabled === false),
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { esKuery } from '../../../../../src/plugins/data/public';
|
||||
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
|
||||
import type { IndexPattern } from '../../../../../src/plugins/data/public';
|
||||
import { combineFiltersAndUserSearch, stringifyKueries } from '../../common/lib';
|
||||
|
||||
|
@ -39,9 +39,9 @@ export const useUpdateKueryString = (
|
|||
// this error will be actually shown in UI for user to see
|
||||
try {
|
||||
if ((filterQueryString || urlFilters) && indexPattern) {
|
||||
const ast = esKuery.fromKueryExpression(combinedFilterString);
|
||||
const ast = fromKueryExpression(combinedFilterString);
|
||||
|
||||
const elasticsearchQuery = esKuery.toElasticsearchQuery(ast, indexPattern);
|
||||
const elasticsearchQuery = toElasticsearchQuery(ast, indexPattern);
|
||||
|
||||
esFilters = JSON.stringify(elasticsearchQuery);
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ import datemath from '@elastic/datemath';
|
|||
import { schema } from '@kbn/config-schema';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { JsonObject } from '@kbn/utility-types';
|
||||
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
|
||||
import { ALERT_REASON } from '@kbn/rule-data-utils';
|
||||
import { UptimeAlertTypeFactory } from './types';
|
||||
import { esKuery } from '../../../../../../src/plugins/data/server';
|
||||
import {
|
||||
StatusCheckFilters,
|
||||
Ping,
|
||||
|
@ -99,7 +99,7 @@ export const generateFilterDSL = async (
|
|||
getIndexPattern: () => Promise<IndexPatternTitleAndFields | undefined>,
|
||||
filters: StatusCheckFilters,
|
||||
search: string
|
||||
): Promise<JsonObject | undefined> => {
|
||||
) => {
|
||||
const filtersExist = hasFilters(filters);
|
||||
if (!filtersExist && !search) return undefined;
|
||||
|
||||
|
@ -110,10 +110,7 @@ export const generateFilterDSL = async (
|
|||
|
||||
const combinedString = combineFiltersAndUserSearch(filterString, search);
|
||||
|
||||
return esKuery.toElasticsearchQuery(
|
||||
esKuery.fromKueryExpression(combinedString ?? ''),
|
||||
await getIndexPattern()
|
||||
);
|
||||
return toElasticsearchQuery(fromKueryExpression(combinedString ?? ''), await getIndexPattern());
|
||||
};
|
||||
|
||||
export const formatFilterString = async (
|
||||
|
@ -349,7 +346,7 @@ export const statusCheckAlertFactory: UptimeAlertTypeFactory<ActionGroupIds> = (
|
|||
timestampRange,
|
||||
numTimes,
|
||||
locations: [],
|
||||
filters: filterString,
|
||||
filters: filterString as JsonObject,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue