Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getEsQueryBody: function (queryString, filters, fields, exclude) {
let esbResult = {}
if (queryString === false) {
esbResult = esb.boolQuery().must(esb.matchAllQuery())
} else if (exclude) {
let excludes = [
esb.termQuery('type', exclude.type)
]
if (exclude.field) {
excludes.push(esb.existsQuery(exclude.field))
}
esbResult = esb.boolQuery().must([
esb.multiMatchQuery(fields, queryString),
esb.boolQuery().mustNot(esb.boolQuery().must(excludes))
])
} else {
esbResult = esb.boolQuery().must(esb.multiMatchQuery(fields, queryString))
}
if (Object.keys(filters).length > 0) {
for (let filterName in filters) {
addFilter(esbResult, filters[filterName], filterName)
}
}
return esb.requestBodySearch().query(
esbResult