mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[KQL] Define KqlContext type (#135273)
This commit is contained in:
parent
54d5cc48ea
commit
c477a90eca
10 changed files with 36 additions and 19 deletions
|
@ -10,7 +10,7 @@ import { JsonObject } from '@kbn/utility-types';
|
|||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { nodeTypes } from '../node_types';
|
||||
import { KQLSyntaxError } from '../kuery_syntax_error';
|
||||
import { KueryNode, KueryParseOptions, KueryQueryOptions } from '../types';
|
||||
import type { KqlContext, KueryNode, KueryParseOptions, KueryQueryOptions } from '../types';
|
||||
|
||||
import { parse as parseKuery } from '../grammar';
|
||||
import { DataViewBase } from '../..';
|
||||
|
@ -68,7 +68,7 @@ export const toElasticsearchQuery = (
|
|||
node: KueryNode,
|
||||
indexPattern?: DataViewBase,
|
||||
config: KueryQueryOptions = {},
|
||||
context?: Record<string, any>
|
||||
context?: KqlContext
|
||||
): JsonObject => {
|
||||
if (!node || !node.type || !nodeTypes[node.type]) {
|
||||
return toElasticsearchQuery(nodeTypes.function.buildNode('and', []), indexPattern);
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
*/
|
||||
|
||||
import * as ast from '../ast';
|
||||
import { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import type { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import type { KqlContext } from '../types';
|
||||
|
||||
export function buildNodeParams(children: KueryNode[]) {
|
||||
return {
|
||||
|
@ -19,7 +20,7 @@ export function toElasticsearchQuery(
|
|||
node: KueryNode,
|
||||
indexPattern?: DataViewBase,
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
context: KqlContext = {}
|
||||
) {
|
||||
const { filtersInMustClause } = config;
|
||||
const children = node.arguments || [];
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
*/
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { DataViewFieldBase, DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import type { DataViewFieldBase, DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import * as literal from '../node_types/literal';
|
||||
import type { KqlContext } from '../types';
|
||||
|
||||
export function buildNodeParams(fieldName: string) {
|
||||
return {
|
||||
|
@ -20,7 +21,7 @@ export function toElasticsearchQuery(
|
|||
node: KueryNode,
|
||||
indexPattern?: DataViewBase,
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
context: KqlContext = {}
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const {
|
||||
arguments: [fieldNameArg],
|
||||
|
|
|
@ -12,10 +12,10 @@ import { getPhraseScript } from '../../filters';
|
|||
import { getFields } from './utils/get_fields';
|
||||
import { getTimeZoneFromSettings, getDataViewFieldSubtypeNested } from '../../utils';
|
||||
import { getFullFieldNameNode } from './utils/get_full_field_name_node';
|
||||
import { DataViewBase, KueryNode, DataViewFieldBase, KueryQueryOptions } from '../..';
|
||||
import type { DataViewBase, KueryNode, DataViewFieldBase, KueryQueryOptions } from '../..';
|
||||
import type { KqlContext } from '../types';
|
||||
|
||||
import * as ast from '../ast';
|
||||
|
||||
import * as literal from '../node_types/literal';
|
||||
import * as wildcard from '../node_types/wildcard';
|
||||
|
||||
|
@ -42,7 +42,7 @@ export function toElasticsearchQuery(
|
|||
node: KueryNode,
|
||||
indexPattern?: DataViewBase,
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
context: KqlContext = {}
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const {
|
||||
arguments: [fieldNameArg, valueArg, isPhraseArg],
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as ast from '../ast';
|
||||
import * as literal from '../node_types/literal';
|
||||
import { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import type { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import type { KqlContext } from '../types';
|
||||
|
||||
export function buildNodeParams(path: any, child: any) {
|
||||
const pathNode =
|
||||
|
@ -23,7 +24,7 @@ export function toElasticsearchQuery(
|
|||
node: KueryNode,
|
||||
indexPattern?: DataViewBase,
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
context: KqlContext = {}
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const [path, child] = node.arguments;
|
||||
const stringPath = ast.toElasticsearchQuery(path) as unknown as string;
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as ast from '../ast';
|
||||
import { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import type { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import type { KqlContext } from '../types';
|
||||
|
||||
export function buildNodeParams(child: KueryNode) {
|
||||
return {
|
||||
|
@ -20,7 +21,7 @@ export function toElasticsearchQuery(
|
|||
node: KueryNode,
|
||||
indexPattern?: DataViewBase,
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
context: KqlContext = {}
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const [argument] = node.arguments;
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as ast from '../ast';
|
||||
import { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import type { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import type { KqlContext } from '../types';
|
||||
|
||||
export function buildNodeParams(children: KueryNode[]) {
|
||||
return {
|
||||
|
@ -20,7 +21,7 @@ export function toElasticsearchQuery(
|
|||
node: KueryNode,
|
||||
indexPattern?: DataViewBase,
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
context: KqlContext = {}
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const children = node.arguments || [];
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import { getFields } from './utils/get_fields';
|
|||
import { getDataViewFieldSubtypeNested, getTimeZoneFromSettings } from '../../utils';
|
||||
import { getFullFieldNameNode } from './utils/get_full_field_name_node';
|
||||
import type { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import type { KqlContext } from '../types';
|
||||
|
||||
export function buildNodeParams(
|
||||
fieldName: string,
|
||||
|
@ -30,7 +31,7 @@ export function toElasticsearchQuery(
|
|||
node: KueryNode,
|
||||
indexPattern?: DataViewBase,
|
||||
config: KueryQueryOptions = {},
|
||||
context: Record<string, any> = {}
|
||||
context: KqlContext = {}
|
||||
): estypes.QueryDslQueryContainer {
|
||||
const [fieldNameArg, operatorArg, valueArg] = node.arguments;
|
||||
const fullFieldNameArg = getFullFieldNameNode(
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
import _ from 'lodash';
|
||||
|
||||
import { functions } from '../functions';
|
||||
import { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import { FunctionName, FunctionTypeBuildNode } from './types';
|
||||
import type { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
|
||||
import type { FunctionName, FunctionTypeBuildNode } from './types';
|
||||
import type { KqlContext } from '../types';
|
||||
|
||||
export function buildNode(functionName: FunctionName, ...args: any[]) {
|
||||
const kueryFunction = functions[functionName];
|
||||
|
@ -47,7 +48,7 @@ export function toElasticsearchQuery(
|
|||
node: KueryNode,
|
||||
indexPattern?: DataViewBase,
|
||||
config?: KueryQueryOptions,
|
||||
context?: Record<string, any>
|
||||
context?: KqlContext
|
||||
) {
|
||||
const kueryFunction = functions[node.function as FunctionName];
|
||||
return kueryFunction.toElasticsearchQuery(node, indexPattern, config, context);
|
||||
|
|
|
@ -47,3 +47,13 @@ export interface KueryQueryOptions {
|
|||
*/
|
||||
nestedIgnoreUnmapped?: boolean;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface KqlContext {
|
||||
nested?: {
|
||||
/**
|
||||
* For nested queries, we pass along the path to the nested document so we can properly craft the query DSL.
|
||||
*/
|
||||
path: string;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue