From 91a3e87aa933590971c562f06f7cb0efbf4528d4 Mon Sep 17 00:00:00 2001 From: Wylie Conlon Date: Tue, 9 Jul 2019 17:57:03 -0400 Subject: [PATCH] Fix usage of Filters aggregation by Terms' Other bucket --- .../buckets/_terms_other_bucket_helper.js | 73 +++++++++---------- .../buckets/_terms_other_bucket_helper.js | 3 + .../ui/public/agg_types/buckets/filters.js | 8 +- 3 files changed, 40 insertions(+), 44 deletions(-) diff --git a/src/legacy/ui/public/agg_types/__tests__/buckets/_terms_other_bucket_helper.js b/src/legacy/ui/public/agg_types/__tests__/buckets/_terms_other_bucket_helper.js index d6840699074b4..d5acdb492c120 100644 --- a/src/legacy/ui/public/agg_types/__tests__/buckets/_terms_other_bucket_helper.js +++ b/src/legacy/ui/public/agg_types/__tests__/buckets/_terms_other_bucket_helper.js @@ -165,20 +165,16 @@ describe('Terms Agg Other bucket helper', () => { filters: { filters: { '': { - 'bool': { - 'must': [{ - 'exists': { - 'field': 'machine.os.raw', - } - }], - 'filter': [], - 'should': [], - 'must_not': [ - { 'match_phrase': { 'machine.os.raw': { 'query': 'ios' } } }, - { 'match_phrase': { 'machine.os.raw': { 'query': 'win xp' } } } + bool: { + must: [{ exists: { field: 'machine.os.raw' } }], + filter: [], + should: [], + must_not: [ + { match_phrase: { 'machine.os.raw': { query: 'ios' } } }, + { match_phrase: { 'machine.os.raw': { query: 'win xp' } } } ] } - } + }, } } }; @@ -192,39 +188,36 @@ describe('Terms Agg Other bucket helper', () => { const expectedResponse = { 'other-filter': { aggs: undefined, - 'filters': { - 'filters': { + filters: { + filters: { '-IN': { - 'bool': { - 'must': [ - { match_phrase: { 'geo.src': { 'query': 'IN' } } }, - { - 'exists': { - 'field': 'machine.os.raw', - } - } - ], 'filter': [], - 'should': [], - 'must_not': [ - { 'match_phrase': { 'machine.os.raw': { 'query': 'ios' } } }, - { 'match_phrase': { 'machine.os.raw': { 'query': 'win xp' } } } + bool: { + must: [ + { match_phrase: { 'geo.src': { query: 'IN' } } }, + { exists: { field: 'machine.os.raw' } } + ], + filter: [], + should: [], + must_not: [ + { match_phrase: { 'machine.os.raw': { query: 'ios' } } }, + { match_phrase: { 'machine.os.raw': { query: 'win xp' } } } ] } - }, '-US': { - 'bool': { - 'must': [ - { 'match_phrase': { 'geo.src': { 'query': 'US' } } }, - { - 'exists': { - 'field': 'machine.os.raw', - } - } - ], 'filter': [], 'should': [], 'must_not': [ - { 'match_phrase': { 'machine.os.raw': { 'query': 'ios' } } }, - { 'match_phrase': { 'machine.os.raw': { 'query': 'win xp' } } } + }, + '-US': { + bool: { + must: [ + { match_phrase: { 'geo.src': { query: 'US' } } }, + { exists: { field: 'machine.os.raw' } } + ], + filter: [], + should: [], + must_not: [ + { match_phrase: { 'machine.os.raw': { query: 'ios' } } }, + { match_phrase: { 'machine.os.raw': { query: 'win xp' } } } ] } - } + }, } } } diff --git a/src/legacy/ui/public/agg_types/buckets/_terms_other_bucket_helper.js b/src/legacy/ui/public/agg_types/buckets/_terms_other_bucket_helper.js index 3e7156abe22bd..b260633ceae9d 100644 --- a/src/legacy/ui/public/agg_types/buckets/_terms_other_bucket_helper.js +++ b/src/legacy/ui/public/agg_types/buckets/_terms_other_bucket_helper.js @@ -110,6 +110,9 @@ const buildOtherBucketAgg = (aggConfigs, aggWithOtherBucket, response) => { const filterAgg = aggConfigs.createAggConfig({ type: 'filters', id: 'other', + params: { + filters: [], + }, }, { addToAggConfigs: false, }); diff --git a/src/legacy/ui/public/agg_types/buckets/filters.js b/src/legacy/ui/public/agg_types/buckets/filters.js index ee1a81b3ed2d5..d7a684db97728 100644 --- a/src/legacy/ui/public/agg_types/buckets/filters.js +++ b/src/legacy/ui/public/agg_types/buckets/filters.js @@ -55,14 +55,14 @@ export const filtersBucketAgg = new BucketAggType({ }); const outFilters = _.transform(inFilters, function (filters, filter) { - let input = _.cloneDeep(filter.input); + const input = _.cloneDeep(filter.input); - if (!input || !input.query) { + if (!input) { console.log('malformed filter agg params, missing "input" query'); // eslint-disable-line no-console return; } - const query = input = buildEsQuery(aggConfig.getIndexPattern(), [input], [], config); + const query = buildEsQuery(aggConfig.getIndexPattern(), [input], [], config); if (!query) { console.log('malformed filter agg params, missing "query" on input'); // eslint-disable-line no-console @@ -73,7 +73,7 @@ export const filtersBucketAgg = new BucketAggType({ const label = filter.label || matchAllLabel || (typeof filter.input.query === 'string' ? filter.input.query : angular.toJson(filter.input.query)); - filters[label] = { query: input }; + filters[label] = { query }; }, {}); if (!_.size(outFilters)) return;