dsl-builder
Version:
OpenSearch Query Builder - Extract from OpenSearch Dashboards
81 lines (80 loc) • 3.27 kB
JavaScript
;
/*
* 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.
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toOpenSearchQuery = exports.buildNodeParams = void 0;
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
const lodash_1 = require("lodash");
const literal = __importStar(require("../node_types/literal"));
function buildNodeParams(fieldName) {
return {
arguments: [literal.buildNode(fieldName)],
};
}
exports.buildNodeParams = buildNodeParams;
function toOpenSearchQuery(node, indexPattern, config = {}, context = {}) {
const { arguments: [fieldNameArg], } = node;
const fullFieldNameArg = {
...fieldNameArg,
value: (context === null || context === void 0 ? void 0 : context.nested)
? `${context.nested.path}.${fieldNameArg.value}`
: fieldNameArg.value,
};
const fieldName = literal.toOpenSearchQuery(fullFieldNameArg);
const field = (0, lodash_1.get)(indexPattern, 'fields', []).find((fld) => fld.name === fieldName);
if (field && field.scripted) {
throw new Error(`Exists query does not support scripted fields`);
}
return {
exists: { field: fieldName },
};
}
exports.toOpenSearchQuery = toOpenSearchQuery;