Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
buildSharedQuery(query: Object) {
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(
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)
))
}
}
}
buildOwnQuery(query) {
if (!this.loadAggregations) {
return query
} else {
return query.setAggs(
FilterBucket(
this.uuid,
this.createAggFilter(query),
...this.fieldContext.wrapAggregations(
this.getTermsBucket(query),
CardinalityMetric(`${this.key}_count`, this.key)
)
)
)
}
}
buildOwnQuery(query) {
const val = this.state.getValue();
const min = val.min;
const max = val.max;
let otherFilters = query.getFiltersWithoutKeys(this.key);
let filters = BoolMust([
otherFilters,
RangeQuery(this.options.field,{
gte:min,
lt: this.addOneDay(val.max),
format: 'yyyy-MM-dd'
})
]);
const metric = CardinalityMetric(this.key, this.options.field);
return query.setAggs(FilterBucket(
this.key,
filters,
metric
));
}
}
createInnerRangeBucket() {
let metric
if (this.options.loadHistogram) {
metric = HistogramBucket(this.key, this.options.field, {
interval: this.getInterval(),
min_doc_count: 0,
extended_bounds: {
min: this.options.min,
max: this.options.max
}
})
} else {
metric = CardinalityMetric(this.key, this.options.field)
}
return metric
}
}