Skip to content

Commit

Permalink
Ensure Other bucket works on scripted fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers committed Jul 9, 2020
1 parent 43c6fbf commit a1733e8
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 @@ -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

0 comments on commit a1733e8

Please sign in to comment.