Skip to content

Commit

Permalink
Merge pull request elastic#8181 from nreese/ignore_filter
Browse files Browse the repository at this point in the history
ignore filters if index does not contain field
  • Loading branch information
w33ble authored Sep 16, 2016
2 parents aa10e6c + c84ba5f commit f2c7abe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/ui/public/courier/data_source/search_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SearchRequestProvider from '../fetch/request/search';
import SegmentedRequestProvider from '../fetch/request/segmented';
import SearchStrategyProvider from '../fetch/strategy/search';

export default function SearchSourceFactory(Promise, Private) {
export default function SearchSourceFactory(Promise, Private, config) {
let SourceAbstract = Private(AbstractDataSourceProvider);
let SearchRequest = Private(SearchRequestProvider);
let SegmentedRequest = Private(SegmentedRequestProvider);
Expand Down Expand Up @@ -150,8 +150,19 @@ export default function SearchSourceFactory(Promise, Private) {

switch (key) {
case 'filter':
let verifiedFilters = val;
if (config.get('courier:ignoreFilterIfFieldNotInIndex')) {
if (!_.isArray(val)) val = [val];
verifiedFilters = val.filter(function (el) {
if ('meta' in el && 'index' in state) {
const field = state.index.fields.byName[el.meta.key];
if (!field) return false;
}
return true;
});
}
// user a shallow flatten to detect if val is an array, and pull the values out if it is
state.filters = _([ state.filters || [], val ])
state.filters = _([ state.filters || [], verifiedFilters ])
.flatten()
// Yo Dawg! I heard you needed to filter out your filters
.reject(function (filter) {
Expand Down
7 changes: 7 additions & 0 deletions src/ui/settings/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ export default function defaultSettingsProvider() {
'elasticsearch. This setting attempts to prevent the list of segments from getting too long, which might ' +
'cause requests to take much longer to process'
},
'courier:ignoreFilterIfFieldNotInIndex': {
value: false,
description: 'This configuration enhances support for dashboards containing visualizations accessing dissimilar indexes. ' +
'When set to false, all filters are applied to all visualizations. ' +
'When set to true, filter(s) will be ignored for a visualization ' +
'when the visualization\'s index does not contain the filtering field.'
},
'fields:popularLimit': {
value: 10,
description: 'The top N most popular fields to show',
Expand Down

0 comments on commit f2c7abe

Please sign in to comment.