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

Fix bug in Filters aggregation and Terms aggregation with Other bucket #40698

Merged
merged 1 commit into from
Jul 10, 2019
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 @@ -165,20 +165,16 @@ describe('Terms Agg Other bucket helper', () => {
filters: {
filters: {
'': {
'bool': {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just reformatting

'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' } } }
]
}
}
},
}
}
};
Expand All @@ -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' } } }
]
}
}
},
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ const buildOtherBucketAgg = (aggConfigs, aggWithOtherBucket, response) => {
const filterAgg = aggConfigs.createAggConfig({
type: 'filters',
id: 'other',
params: {
filters: [],
},
}, {
addToAggConfigs: false,
});
Expand Down
8 changes: 4 additions & 4 deletions src/legacy/ui/public/agg_types/buckets/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down