Skip to content

Commit

Permalink
[courier] translate filters and filter aggs to work with es master
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Feb 5, 2016
1 parent 15c94b4 commit 7aee4a5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/ui/public/courier/data_source/_abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,21 @@ define(function (require) {
return _.omit(filter, ['meta']);
};

/**
* Translate a filter into a query to support es 3+
* @param {Object} filter - The fitler to translate
* @return {Object} the query version of that filter
*/
var translateToQuery = function (filter) {
if (!filter) return;

if (filter.query) {
return filter.query;
}

return filter;
};

// switch to filtered query if there are filters
if (flatState.filters) {
if (flatState.filters.length) {
Expand All @@ -326,19 +341,40 @@ define(function (require) {
[flatState.body.query].concat(
(flatState.filters || [])
.filter(filterNegate(false))
.map(translateToQuery)
.map(cleanFilter)
)
),
must_not: (
(flatState.filters || [])
.filter(filterNegate(true))
.map(translateToQuery)
.map(cleanFilter)
)
}
};
}
delete flatState.filters;
}

// re-write filters within filter aggregations
(function recurse(aggBranch) {
if (!aggBranch) return;
Object.keys(aggBranch).forEach(function (id) {
const agg = aggBranch[id];

if (agg.filters) {
// translate filters aggregations
const filters = agg.filters.filters;

Object.keys(filters).forEach(function (filterId) {
filters[filterId] = translateToQuery(filters[filterId]);
});
}

recurse(agg.aggs);
});
}(flatState.body.aggs || flatState.body.aggregations));
}

return flatState;
Expand Down
1 change: 0 additions & 1 deletion src/ui/public/courier/data_source/_decorate_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ define(function (require) {
};
};
});

0 comments on commit 7aee4a5

Please sign in to comment.