UNPKG

dsl-builder

Version:

OpenSearch Query Builder - Extract from OpenSearch Dashboards

39 lines (38 loc) 1.28 kB
/* * SPDX-License-Identifier: Apache-2.0 * * The OpenSearch Contributors require contributions made to * this file be licensed under the Apache-2.0 license or a * compatible open source license. * * Any modifications Copyright OpenSearch Contributors. See * GitHub history for details. */ import * as ast from '../ast'; import * as literal from '../node_types/literal'; export function buildNodeParams(path, child) { const pathNode = typeof path === 'string' ? ast.fromLiteralExpression(path) : literal.buildNode(path); return { arguments: [pathNode, child], }; } export function toOpenSearchQuery(node, indexPattern, config = {}, context = {}) { var _a; const [path, child] = node.arguments; const stringPath = ast.toOpenSearchQuery(path); const fullPath = ((_a = context === null || context === void 0 ? void 0 : context.nested) === null || _a === void 0 ? void 0 : _a.path) ? `${context.nested.path}.${stringPath}` : stringPath; return { nested: { path: fullPath, query: ast.toOpenSearchQuery(child, indexPattern, config, { ...context, nested: { path: fullPath }, }), score_mode: 'none', }, }; }