Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data.search.aggs] Ensure Other bucket works on scripted fields. #71329

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,83 @@ describe('Terms Agg Other bucket helper', () => {
}
});

test('excludes exists filter for scripted fields', () => {
const aggConfigs = getAggConfigs(nestedTerm.aggs);
aggConfigs.aggs[1].params.field.scripted = true;
const agg = buildOtherBucketAgg(
aggConfigs,
aggConfigs.aggs[1] as IBucketAggConfig,
nestedTermResponse
);
const expectedResponse = {
'other-filter': {
aggs: undefined,
filters: {
filters: {
'-IN': {
bool: {
must: [],
filter: [{ match_phrase: { 'geo.src': 'IN' } }],
should: [],
must_not: [
{
script: {
script: {
lang: undefined,
params: { value: 'ios' },
source: '(undefined) == value',
},
},
},
{
script: {
script: {
lang: undefined,
params: { value: 'win xp' },
source: '(undefined) == value',
},
},
},
],
},
},
'-US': {
bool: {
must: [],
filter: [{ match_phrase: { 'geo.src': 'US' } }],
should: [],
must_not: [
{
script: {
script: {
lang: undefined,
params: { value: 'ios' },
source: '(undefined) == value',
},
},
},
{
script: {
script: {
lang: undefined,
params: { value: 'win xp' },
source: '(undefined) == value',
},
},
},
],
},
},
},
},
},
};
expect(agg).toBeDefined();
if (agg) {
expect(agg()).toEqual(expectedResponse);
}
});

test('returns false when nested terms agg has no buckets', () => {
const aggConfigs = getAggConfigs(nestedTerm.aggs);
const agg = buildOtherBucketAgg(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,12 @@ export const buildOtherBucketAgg = (
return;
}

if (
!aggWithOtherBucket.params.missingBucket ||
agg.buckets.some((bucket: { key: string }) => bucket.key === '__missing__')
) {
const hasScriptedField = !!aggWithOtherBucket.params.field.scripted;
const hasMissingBucket = !!aggWithOtherBucket.params.missingBucket;
const hasMissingBucketKey = agg.buckets.some(
(bucket: { key: string }) => bucket.key === '__missing__'
);
if (!hasScriptedField && (!hasMissingBucket || hasMissingBucketKey)) {
filters.push(
buildExistsFilter(
aggWithOtherBucket.params.field,
Expand Down