Put filters back in the filter context where they belong (#42095) (#42496)

Filters were never really meant to take part in scoring in the first place. This PR puts filters back in the filter context where they were in 4.x so they can benefit from the filter cache.
This commit is contained in:
Matt Bargar 2019-08-02 10:36:00 -04:00 committed by GitHub
parent 696928676c
commit 65258a4ed8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 22 deletions

View file

@ -60,10 +60,10 @@ describe('build query', function () {
bool: {
must: [
decorateQuery(luceneStringToDsl('bar:baz'), config.queryStringOptions),
{ match_all: {} },
],
filter: [
toElasticsearchQuery(fromKueryExpression('extension:jpg'), indexPattern),
{ match_all: {} },
],
should: [],
must_not: [],
@ -90,9 +90,8 @@ describe('build query', function () {
bool: {
must: [
decorateQuery(luceneStringToDsl('extension:jpg'), config.queryStringOptions),
{ match_all: {} },
],
filter: [],
filter: [{ match_all: {} }],
should: [],
must_not: [],
}
@ -122,9 +121,11 @@ describe('build query', function () {
bool: {
must: [
decorateQuery(luceneStringToDsl('@timestamp:"2019-03-23T13:18:00"'), config.queryStringOptions, config.dateFormatTZ),
],
filter: [
toElasticsearchQuery(fromKueryExpression('@timestamp:"2019-03-23T13:18:00"'), indexPattern, config),
{ match_all: {} }
],
filter: [toElasticsearchQuery(fromKueryExpression('@timestamp:"2019-03-23T13:18:00"'), indexPattern, config)],
should: [],
must_not: [],
}

View file

@ -52,7 +52,7 @@ describe('build query', function () {
const result = buildQueryFromFilters(filters);
expect(result.must).to.eql(expectedESQueries);
expect(result.filter).to.eql(expectedESQueries);
});
it('should place negated filters in the must_not clause', function () {
@ -86,7 +86,7 @@ describe('build query', function () {
const result = buildQueryFromFilters(filters);
expect(result.must).to.eql(expectedESQueries);
expect(result.filter).to.eql(expectedESQueries);
});
it('should migrate deprecated match syntax', function () {
@ -105,7 +105,7 @@ describe('build query', function () {
const result = buildQueryFromFilters(filters);
expect(result.must).to.eql(expectedESQueries);
expect(result.filter).to.eql(expectedESQueries);
});
it('should not add query:queryString:options to query_string filters', function () {
@ -119,7 +119,7 @@ describe('build query', function () {
const result = buildQueryFromFilters(filters);
expect(result.must).to.eql(expectedESQueries);
expect(result.filter).to.eql(expectedESQueries);
});
});
});

View file

@ -61,7 +61,8 @@ const cleanFilter = function (filter) {
export function buildQueryFromFilters(filters = [], indexPattern, ignoreFilterIfFieldNotInIndex) {
return {
must: filters
must: [],
filter: filters
.filter(filterNegate(false))
.filter(filter => !ignoreFilterIfFieldNotInIndex || filterMatchesIndex(filter, indexPattern))
.map(translateToQuery)
@ -69,7 +70,6 @@ export function buildQueryFromFilters(filters = [], indexPattern, ignoreFilterIf
.map(filter => {
return migrateFilter(filter, indexPattern);
}),
filter: [],
should: [],
must_not: filters
.filter(filterNegate(true))

View file

@ -126,8 +126,7 @@ describe('query(req, panel, series)', () => {
size: 0,
query: {
bool: {
filter: [],
must: [
filter: [
{
bool: {
must: [
@ -139,6 +138,8 @@ describe('query(req, panel, series)', () => {
],
},
},
],
must: [
{
range: {
timestamp: {
@ -218,8 +219,7 @@ describe('query(req, panel, series)', () => {
size: 0,
query: {
bool: {
filter: [],
must: [
filter: [
{
bool: {
must: [
@ -231,6 +231,8 @@ describe('query(req, panel, series)', () => {
],
},
},
],
must: [
{
range: {
timestamp: {

View file

@ -106,8 +106,7 @@ describe('buildRequestBody(req)', () => {
size: 0,
query: {
bool: {
filter: [],
must: [
filter: [
{
bool: {
must: [
@ -121,6 +120,8 @@ describe('buildRequestBody(req)', () => {
must_not: [],
},
},
],
must: [
{
range: {
'@timestamp': {

View file

@ -182,8 +182,8 @@ describe('Terms Agg Other bucket helper', () => {
filters: {
'': {
bool: {
must: [{ exists: { field: 'machine.os.raw' } }],
filter: [],
must: [],
filter: [{ exists: { field: 'machine.os.raw' } }],
should: [],
must_not: [
{ match_phrase: { 'machine.os.raw': { query: 'ios' } } },
@ -208,11 +208,11 @@ describe('Terms Agg Other bucket helper', () => {
filters: {
'-IN': {
bool: {
must: [
must: [],
filter: [
{ match_phrase: { 'geo.src': { query: 'IN' } } },
{ exists: { field: 'machine.os.raw' } }
],
filter: [],
should: [],
must_not: [
{ match_phrase: { 'machine.os.raw': { query: 'ios' } } },
@ -222,11 +222,11 @@ describe('Terms Agg Other bucket helper', () => {
},
'-US': {
bool: {
must: [
must: [],
filter: [
{ match_phrase: { 'geo.src': { query: 'US' } } },
{ exists: { field: 'machine.os.raw' } }
],
filter: [],
should: [],
must_not: [
{ match_phrase: { 'machine.os.raw': { query: 'ios' } } },