Skip to content

Commit

Permalink
Ensure Other bucket works on scripted fields. (#71329) (#71498)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers authored Jul 13, 2020
1 parent 2d371c2 commit c8c0dce
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,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

0 comments on commit c8c0dce

Please sign in to comment.