Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'elastic-builder' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
if (item.length > 0) {
return item
}
})
// Match any terms.
esbResult = esbResult.filter(esb.termsQuery(filterName, filterVals))
// Match all terms.
// esbResult = esbResult.should(esb.termsQuery(filterName, filterVals))
// esbResult = esbResult.minimumShouldMatch(filterField.length)
} else {
let filterField = filter.values.slice()
esbResult = esbResult.filter(esb.termQuery(filterName, filterField))
}
break
case 'multiMatch':
esbResult = esbResult.must(esb.multiMatchQuery(filter.fields, filter.values))
break
case 'ids':
esbResult = esbResult.filter(esb.idsQuery(filter.fields, filter.values))
break
case 'integer':
esbResult = esbResult.filter(esb.rangeQuery(filterName)[operator](filter.values))
break
default:
}
}
case 'term':
if (Array.isArray(filter.values)) {
const filterVals = filter.values.map((item) => {
// Check that filter fields aren't empty.
if (item.length > 0) {
return item
}
})
// Match any terms.
esbResult = esbResult.filter(esb.termsQuery(filterName, filterVals))
// Match all terms.
// esbResult = esbResult.should(esb.termsQuery(filterName, filterVals))
// esbResult = esbResult.minimumShouldMatch(filterField.length)
} else {
let filterField = filter.values.slice()
esbResult = esbResult.filter(esb.termQuery(filterName, filterField))
}
break
case 'multiMatch':
esbResult = esbResult.must(esb.multiMatchQuery(filter.fields, filter.values))
break
case 'ids':
esbResult = esbResult.filter(esb.idsQuery(filter.fields, filter.values))
break
case 'integer':
esbResult = esbResult.filter(esb.rangeQuery(filterName)[operator](filter.values))
break
default:
}
}
})
// Match any terms.
esbResult = esbResult.filter(esb.termsQuery(filterName, filterVals))
// Match all terms.
// esbResult = esbResult.should(esb.termsQuery(filterName, filterVals))
// esbResult = esbResult.minimumShouldMatch(filterField.length)
} else {
let filterField = filter.values.slice()
esbResult = esbResult.filter(esb.termQuery(filterName, filterField))
}
break
case 'multiMatch':
esbResult = esbResult.must(esb.multiMatchQuery(filter.fields, filter.values))
break
case 'ids':
esbResult = esbResult.filter(esb.idsQuery(filter.fields, filter.values))
break
case 'integer':
esbResult = esbResult.filter(esb.rangeQuery(filterName)[operator](filter.values))
break
default:
}
}
const addFilter = function (esbResult, filter, filterName) {
let operator = filter.operator
switch (filter.type) {
case 'date':
if (moment(filter.values).isValid() || filter.values === 'now') {
esbResult = esbResult.filter(esb.rangeQuery(filterName)[operator](filter.values))
}
break
case 'term':
if (Array.isArray(filter.values)) {
const filterVals = filter.values.map((item) => {
// Check that filter fields aren't empty.
if (item.length > 0) {
return item
}
})
// Match any terms.
esbResult = esbResult.filter(esb.termsQuery(filterName, filterVals))
// Match all terms.
// esbResult = esbResult.should(esb.termsQuery(filterName, filterVals))
// esbResult = esbResult.minimumShouldMatch(filterField.length)
} else {
switch (filter.type) {
case 'date':
if (moment(filter.values).isValid() || filter.values === 'now') {
esbResult = esbResult.filter(esb.rangeQuery(filterName)[operator](filter.values))
}
break
case 'term':
if (Array.isArray(filter.values)) {
const filterVals = filter.values.map((item) => {
// Check that filter fields aren't empty.
if (item.length > 0) {
return item
}
})
// Match any terms.
esbResult = esbResult.filter(esb.termsQuery(filterName, filterVals))
// Match all terms.
// esbResult = esbResult.should(esb.termsQuery(filterName, filterVals))
// esbResult = esbResult.minimumShouldMatch(filterField.length)
} else {
let filterField = filter.values.slice()
esbResult = esbResult.filter(esb.termQuery(filterName, filterField))
}
break
case 'multiMatch':
esbResult = esbResult.must(esb.multiMatchQuery(filter.fields, filter.values))
break
case 'ids':
esbResult = esbResult.filter(esb.idsQuery(filter.fields, filter.values))
break
case 'integer':
esbResult = esbResult.filter(esb.rangeQuery(filterName)[operator](filter.values))
addAgg: function (body, inputField) {
return body.agg(esb.termsAggregation(inputField.model, inputField.model).order('_key', 'asc').size(30)) // [SDPA-1999] TODO: Size should probaly come from the model
},
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
)
},
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
)
},
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
)
},
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
)
},