Skip to content

Commit

Permalink
[search source] Stop building invalid queries and then rewriting them (
Browse files Browse the repository at this point in the history
…#60954) (#64259)

* Stop rewriting invalid filters in search source

* Fix type issue

* Use automated fixing tool

* Update test

* Fix test

* Fix docs

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
Wylie Conlon and elasticmachine authored Apr 23, 2020
1 parent 8c4b8f4 commit 1a662d0
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export const createFilterFilters = (aggConfig: IBucketAggConfig, key: string) =>
const indexPattern = aggConfig.getIndexPattern();

if (filter && indexPattern && indexPattern.id) {
return buildQueryFilter(filter.query, indexPattern.id, key);
return buildQueryFilter(filter, indexPattern.id, key);
}
};
2 changes: 1 addition & 1 deletion src/plugins/data/public/search/aggs/buckets/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const getFiltersBucketAgg = ({
(typeof filter.input.query === 'string'
? filter.input.query
: toAngularJSON(filter.input.query));
filters[label] = { query };
filters[label] = query;
},
{}
);
Expand Down
20 changes: 0 additions & 20 deletions src/plugins/data/public/search/search_source/search_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,26 +447,6 @@ export class SearchSource {
delete searchRequest.highlightAll;
}

const translateToQuery = (filter: Filter) => filter && (filter.query || filter);

// 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: aggFilters } = agg.filters;
Object.keys(aggFilters).forEach(filterId => {
aggFilters[filterId] = translateToQuery(aggFilters[filterId]);
});
}

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

return searchRequest;
}

Expand Down

0 comments on commit 1a662d0

Please sign in to comment.