From 3dfcf5dc9850e1b16c24215c0737ea4ea9ef9720 Mon Sep 17 00:00:00 2001 From: Matt Bargar Date: Fri, 4 Aug 2017 14:45:21 -0400 Subject: [PATCH] Remove simple_query_string hack now that multi_match supports * (#13285) --- .../public/kuery/functions/__tests__/and.js | 5 +-- src/ui/public/kuery/functions/__tests__/is.js | 34 ++++++------------- .../public/kuery/functions/__tests__/not.js | 5 +-- src/ui/public/kuery/functions/__tests__/or.js | 5 +-- src/ui/public/kuery/functions/is.js | 16 +++------ 5 files changed, 25 insertions(+), 40 deletions(-) diff --git a/src/ui/public/kuery/functions/__tests__/and.js b/src/ui/public/kuery/functions/__tests__/and.js index 8d497f92fbb0..a14de59f775e 100644 --- a/src/ui/public/kuery/functions/__tests__/and.js +++ b/src/ui/public/kuery/functions/__tests__/and.js @@ -4,6 +4,7 @@ import { nodeTypes } from '../../node_types'; import * as ast from '../../ast'; import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; import ngMock from 'ng_mock'; +import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal'; let indexPattern; @@ -54,11 +55,11 @@ describe('kuery functions', function () { it('should wrap a literal argument with an "is" function targeting all fields', function () { const literalFoo = nodeTypes.literal.buildNode('foo'); + const expectedChild = ast.toElasticsearchQuery(nodeTypes.function.buildNode('is', '*', 'foo'), indexPattern); const node = nodeTypes.function.buildNode('and', [literalFoo]); const result = and.toElasticsearchQuery(node, indexPattern); const resultChild = result.bool.filter[0]; - expect(resultChild).to.have.property('simple_query_string'); - expect(resultChild.simple_query_string.all_fields).to.be(true); + expectDeepEqual(resultChild, expectedChild); }); }); diff --git a/src/ui/public/kuery/functions/__tests__/is.js b/src/ui/public/kuery/functions/__tests__/is.js index 29a7569d2271..2d61d93d8082 100644 --- a/src/ui/public/kuery/functions/__tests__/is.js +++ b/src/ui/public/kuery/functions/__tests__/is.js @@ -1,9 +1,9 @@ import expect from 'expect.js'; import * as is from '../is'; import { nodeTypes } from '../../node_types'; -import _ from 'lodash'; import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; import ngMock from 'ng_mock'; +import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal'; let indexPattern; @@ -54,34 +54,22 @@ describe('kuery functions', function () { const node = nodeTypes.function.buildNode('is', '*', '*'); const result = is.toElasticsearchQuery(node, indexPattern); - expect(_.isEqual(expected, result)).to.be(true); + expectDeepEqual(result, expected); }); - it('should return an ES simple_query_string query in all fields mode when fieldName is "*"', function () { + it('should return an ES multi_match query when fieldName is "*"', function () { const expected = { - simple_query_string: { - query: '"200"', - all_fields: true, + multi_match: { + query: 200, + fields: ['*'], + type: 'phrase', + lenient: true, } }; const node = nodeTypes.function.buildNode('is', '*', 200); const result = is.toElasticsearchQuery(node, indexPattern); - expect(_.isEqual(expected, result)).to.be(true); - }); - - // See discussion about kuery escaping for background: - // https://github.com/elastic/kibana/pull/12624#issuecomment-312650307 - it('should ensure the simple_query_string query is wrapped in double quotes to force a phrase search', function () { - const node = nodeTypes.function.buildNode('is', '*', '+response'); - const result = is.toElasticsearchQuery(node, indexPattern); - expect(result.simple_query_string.query).to.be('"+response"'); - }); - - it('already double quoted phrases should not get wrapped a second time', function () { - const node = nodeTypes.function.buildNode('is', '*', '"+response"'); - const result = is.toElasticsearchQuery(node, indexPattern); - expect(result.simple_query_string.query).to.be('"+response"'); + expectDeepEqual(result, expected); }); it('should return an ES exists query when value is "*"', function () { @@ -91,7 +79,7 @@ describe('kuery functions', function () { const node = nodeTypes.function.buildNode('is', 'response', '*'); const result = is.toElasticsearchQuery(node, indexPattern); - expect(_.isEqual(expected, result)).to.be(true); + expectDeepEqual(result, expected); }); it('should return an ES match_phrase query when a concrete fieldName and value are provided', function () { @@ -103,7 +91,7 @@ describe('kuery functions', function () { const node = nodeTypes.function.buildNode('is', 'response', 200); const result = is.toElasticsearchQuery(node, indexPattern); - expect(_.isEqual(expected, result)).to.be(true); + expectDeepEqual(result, expected); }); it('should support scripted fields', function () { diff --git a/src/ui/public/kuery/functions/__tests__/not.js b/src/ui/public/kuery/functions/__tests__/not.js index dc25a7a84e4e..a30909aac926 100644 --- a/src/ui/public/kuery/functions/__tests__/not.js +++ b/src/ui/public/kuery/functions/__tests__/not.js @@ -4,6 +4,7 @@ import { nodeTypes } from '../../node_types'; import * as ast from '../../ast'; import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; import ngMock from 'ng_mock'; +import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal'; let indexPattern; @@ -49,11 +50,11 @@ describe('kuery functions', function () { it('should wrap a literal argument with an "is" function targeting all fields', function () { const literalFoo = nodeTypes.literal.buildNode('foo'); + const expectedChild = ast.toElasticsearchQuery(nodeTypes.function.buildNode('is', '*', 'foo'), indexPattern); const node = nodeTypes.function.buildNode('not', literalFoo); const result = not.toElasticsearchQuery(node, indexPattern); const resultChild = result.bool.must_not; - expect(resultChild).to.have.property('simple_query_string'); - expect(resultChild.simple_query_string.all_fields).to.be(true); + expectDeepEqual(resultChild, expectedChild); }); }); diff --git a/src/ui/public/kuery/functions/__tests__/or.js b/src/ui/public/kuery/functions/__tests__/or.js index 4ee5f5e44e31..ffede80f57dc 100644 --- a/src/ui/public/kuery/functions/__tests__/or.js +++ b/src/ui/public/kuery/functions/__tests__/or.js @@ -4,6 +4,7 @@ import { nodeTypes } from '../../node_types'; import * as ast from '../../ast'; import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; import ngMock from 'ng_mock'; +import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal'; let indexPattern; @@ -54,11 +55,11 @@ describe('kuery functions', function () { it('should wrap a literal argument with an "is" function targeting all fields', function () { const literalFoo = nodeTypes.literal.buildNode('foo'); + const expectedChild = ast.toElasticsearchQuery(nodeTypes.function.buildNode('is', '*', 'foo'), indexPattern); const node = nodeTypes.function.buildNode('or', [literalFoo]); const result = or.toElasticsearchQuery(node, indexPattern); const resultChild = result.bool.should[0]; - expect(resultChild).to.have.property('simple_query_string'); - expect(resultChild.simple_query_string.all_fields).to.be(true); + expectDeepEqual(resultChild, expectedChild); }); it('should require one of the clauses to match', function () { diff --git a/src/ui/public/kuery/functions/is.js b/src/ui/public/kuery/functions/is.js index a64fe194f140..0f58fa7302b5 100644 --- a/src/ui/public/kuery/functions/is.js +++ b/src/ui/public/kuery/functions/is.js @@ -33,13 +33,12 @@ export function toElasticsearchQuery(node, indexPattern) { return { match_all: {} }; } else if (fieldName === '*' && value !== '*') { - const userQuery = String(value); - const query = isDoubleQuoted(userQuery) ? userQuery : `"${userQuery}"`; - return { - simple_query_string: { - query, - all_fields: true + multi_match: { + query: value, + fields: ['*'], + type: 'phrase', + lenient: true, } }; } @@ -68,8 +67,3 @@ export function toKueryExpression(node) { return `${fieldName}:${value}`; } - -function isDoubleQuoted(str) { - return str.startsWith('"') && str.endsWith('"'); -} -