kibana/packages/kbn-es-query/index.ts
Lukas Olson 12e748486c
[KQL] Add support for toKqlExpression (#161601)
## Summary

Resolves https://github.com/elastic/kibana/issues/77971.

Adds a `toKqlExpression` method to the `@kbn/es-query` that allows
generating a KQL expression from an AST node.

Example:

```ts
const node = fromKueryExpression('extension: "jpg"');
const kql = toKqlExpression(node); // 'extension: "jpg"'
```

Note that the generated KQL expression may not exactly match the
original text (whitespace is not preserved, parentheses may be added,
etc.).

### Checklist

Delete any items that are not applicable to this PR.

- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
2023-07-14 13:44:50 -07:00

126 lines
2.6 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
export type {
BoolQuery,
DataViewBase,
DataViewFieldBase,
EsQueryConfig,
EsQueryFiltersConfig,
IFieldSubType,
IFieldSubTypeMulti,
IFieldSubTypeNested,
} from './src/es_query';
export type {
CustomFilter,
ExistsFilter,
FieldFilter,
Filter,
FilterCompareOptions,
FilterMeta,
LatLon,
MatchAllFilter,
PhraseFilter,
PhrasesFilter,
Query,
AggregateQuery,
QueryStringFilter,
RangeFilter,
RangeFilterMeta,
RangeFilterParams,
ScriptedPhraseFilter,
ScriptedRangeFilter,
TimeRange,
CombinedFilter,
} from './src/filters';
export type { DslQuery, KueryNode, KueryParseOptions, KueryQueryOptions } from './src/kuery';
export {
buildEsQuery,
buildQueryFromFilters,
filterToQueryDsl,
decorateQuery,
luceneStringToDsl,
migrateFilter,
fromCombinedFilter,
isOfQueryType,
isOfAggregateQueryType,
getAggregateQueryMode,
getIndexPatternFromSQLQuery,
} from './src/es_query';
export {
COMPARE_ALL_OPTIONS,
FILTERS,
FilterStateStore,
buildCustomFilter,
buildEmptyFilter,
buildExistsFilter,
buildFilter,
buildCombinedFilter,
buildPhraseFilter,
buildPhrasesFilter,
buildQueryFilter,
buildRangeFilter,
cleanFilter,
compareFilters,
dedupFilters,
disableFilter,
enableFilter,
getConvertedValueForField,
getFilterField,
getFilterParams,
getPhraseFilterField,
getPhraseFilterValue,
getPhraseScript,
getRangeScript,
isExistsFilter,
isFilter,
isFilterDisabled,
isFilterPinned,
isFilters,
isMatchAllFilter,
isCombinedFilter,
isPhraseFilter,
isPhrasesFilter,
isQueryStringFilter,
isRangeFilter,
isScriptedPhraseFilter,
isScriptedRangeFilter,
onlyDisabledFiltersChanged,
pinFilter,
toggleFilterDisabled,
toggleFilterNegated,
toggleFilterPinned,
uniqFilters,
unpinFilter,
updateFilter,
extractTimeFilter,
extractTimeRange,
convertRangeFilterToTimeRange,
BooleanRelation,
} from './src/filters';
export {
KQLSyntaxError,
fromKueryExpression,
toKqlExpression,
nodeBuilder,
nodeTypes,
toElasticsearchQuery,
escapeKuery,
} from './src/kuery';
export {
getDataViewFieldSubtypeMulti,
getDataViewFieldSubtypeNested,
isDataViewFieldSubtypeMulti,
isDataViewFieldSubtypeNested,
} from './src/utils';