Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const modifiedQuery = super.buildSharedQuery(query)
/**
* Modify query to perform aggregation on unique users,
* to avoid duplicate counts of multiple work histories or education items
* for the same user
**/
const pieces = nestedField.split(".")
if (pieces.length !== 3) {
throw new Error(`Assumed three pieces but found ${pieces.length}`)
}
const cardinality = CardinalityMetric("count", "user_id")
const aggsContainer = AggsContainer(countName, { reverse_nested: {} }, [
cardinality
])
const termsBucket = TermsBucket(
nestedField,
nestedField,
{},
aggsContainer
)
const nestedBucket = NestedBucket(
"inner",
`${pieces[0]}.${pieces[1]}`,
termsBucket
)
return modifiedQuery.setAggs(
AggsContainer(
`${this.uuid}`,
{
filter: {}
function ReverseNestedTermsBucket(key, field, options) {
const reverseNestedAgg = AggsContainer(REVERSE_NESTED_AGG_KEY, {
reverse_nested: {}
})
return TermsBucket(key, field, options, reverseNestedAgg)
}
buildOwnQuery(query){
if (!this.loadAggregations){
return query
} else {
var filters = this.state.getValue()
let excludedKey = (this.isOrOperator()) ? this.uuid : undefined
return query
.setAggs(FilterBucket(
this.uuid,
query.getFiltersWithoutKeys(excludedKey),
TermsBucket(this.key, this.key, omitBy({
size:this.size,
order:this.getOrder(),
include: this.options.include,
exclude: this.options.exclude,
min_doc_count:this.options.min_doc_count
}, isUndefined)),
CardinalityMetric(this.key+"_count", this.key)
))
}
}
}
BoolMust([
NestedQuery(field, regexpQuery)
]),
NestedBucket("children", field,
FilterBucket("filtered",
BoolMust([
regexpQuery,
{
"range": {
[field + ".level"]: {
gte: startLevel
}
}
}
]),
TermsBucket("terms", field + ".value", {
size: this.options.size
},
TopHitsMetric("hits", {
_source: [field + ".ancestors", "ancestors"],
size: 1
}))
)
)
))
}