@@ -12,10 +12,10 @@ import { getPhraseScript } from '../../filters';
1212import { getFields } from './utils/get_fields' ;
1313import { getTimeZoneFromSettings , getDataViewFieldSubtypeNested } from '../../utils' ;
1414import { getFullFieldNameNode } from './utils/get_full_field_name_node' ;
15- import { DataViewBase , KueryNode , DataViewFieldBase , KueryQueryOptions } from '../..' ;
15+ import type { DataViewBase , KueryNode , DataViewFieldBase , KueryQueryOptions } from '../..' ;
16+ import type { KqlContext } from '../types' ;
1617
1718import * as ast from '../ast' ;
18-
1919import * as literal from '../node_types/literal' ;
2020import * as wildcard from '../node_types/wildcard' ;
2121
@@ -42,15 +42,14 @@ export function toElasticsearchQuery(
4242 node : KueryNode ,
4343 indexPattern ?: DataViewBase ,
4444 config : KueryQueryOptions = { } ,
45- context : Record < string , any > = { }
45+ context : KqlContext = { }
4646) : estypes . QueryDslQueryContainer {
4747 const {
4848 arguments : [ fieldNameArg , valueArg , isPhraseArg ] ,
4949 } = node ;
5050
51- const isExistsQuery = valueArg . type === 'wildcard' && valueArg . value === wildcard . wildcardSymbol ;
52- const isAllFieldsQuery =
53- fieldNameArg . type === 'wildcard' && fieldNameArg . value === wildcard . wildcardSymbol ;
51+ const isExistsQuery = wildcard . isNode ( valueArg ) && wildcard . isLoneWildcard ( valueArg ) ;
52+ const isAllFieldsQuery = wildcard . isNode ( fieldNameArg ) && wildcard . isLoneWildcard ( fieldNameArg ) ;
5453 const isMatchAllQuery = isExistsQuery && isAllFieldsQuery ;
5554
5655 if ( isMatchAllQuery ) {
@@ -65,7 +64,7 @@ export function toElasticsearchQuery(
6564 const value = ! isUndefined ( valueArg ) ? ast . toElasticsearchQuery ( valueArg ) : valueArg ;
6665 const type = isPhraseArg . value ? 'phrase' : 'best_fields' ;
6766 if ( fullFieldNameArg . value === null ) {
68- if ( valueArg . type === ' wildcard' ) {
67+ if ( wildcard . isNode ( valueArg ) ) {
6968 return {
7069 query_string : {
7170 query : wildcard . toQueryStringQuery ( valueArg ) ,
@@ -106,7 +105,7 @@ export function toElasticsearchQuery(
106105 // Wildcards can easily include nested and non-nested fields. There isn't a good way to let
107106 // users handle this themselves so we automatically add nested queries in this scenario.
108107 const subTypeNested = getDataViewFieldSubtypeNested ( field ) ;
109- if ( ! ( fullFieldNameArg . type === 'wildcard' ) || ! subTypeNested ?. nested || context ?. nested ) {
108+ if ( ! wildcard . isNode ( fullFieldNameArg ) || ! subTypeNested ?. nested || context ?. nested ) {
110109 return query ;
111110 } else {
112111 return {
@@ -143,7 +142,7 @@ export function toElasticsearchQuery(
143142 } ,
144143 } ) ,
145144 ] ;
146- } else if ( valueArg . type === ' wildcard' ) {
145+ } else if ( wildcard . isNode ( valueArg ) ) {
147146 return [
148147 ...accumulator ,
149148 wrapWithNestedQuery ( {
0 commit comments