dsl-builder
Version:
OpenSearch Query Builder - Extract from OpenSearch Dashboards
37 lines (36 loc) • 1.16 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.
*/
import * as ast from '../ast';
export function buildNodeParams(children) {
return {
arguments: children,
};
}
export function toOpenSearchQuery(node, indexPattern, config = {}, context = {}) {
const children = node.arguments || [];
// Flatten nested bool queries to reduce nesting
const flattenedQueries = [];
children.forEach((child) => {
const childQuery = ast.toOpenSearchQuery(child, indexPattern, config, context);
// If child returns a bool query with filter, flatten it
if (childQuery.bool && childQuery.bool.filter && Array.isArray(childQuery.bool.filter)) {
flattenedQueries.push(...childQuery.bool.filter);
}
else {
flattenedQueries.push(childQuery);
}
});
return {
bool: {
filter: flattenedQueries,
},
};
}