Skip to content

Commit b187ef9

Browse files
authored
Remove simple_query_string hack now that multi_match supports * (#13285) (#13346)
1 parent 8f2d2cf commit b187ef9

File tree

5 files changed

+25
-40
lines changed

5 files changed

+25
-40
lines changed

src/ui/public/kuery/functions/__tests__/and.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { nodeTypes } from '../../node_types';
44
import * as ast from '../../ast';
55
import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
66
import ngMock from 'ng_mock';
7+
import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal';
78

89
let indexPattern;
910

@@ -54,11 +55,11 @@ describe('kuery functions', function () {
5455

5556
it('should wrap a literal argument with an "is" function targeting all fields', function () {
5657
const literalFoo = nodeTypes.literal.buildNode('foo');
58+
const expectedChild = ast.toElasticsearchQuery(nodeTypes.function.buildNode('is', '*', 'foo'), indexPattern);
5759
const node = nodeTypes.function.buildNode('and', [literalFoo]);
5860
const result = and.toElasticsearchQuery(node, indexPattern);
5961
const resultChild = result.bool.filter[0];
60-
expect(resultChild).to.have.property('simple_query_string');
61-
expect(resultChild.simple_query_string.all_fields).to.be(true);
62+
expectDeepEqual(resultChild, expectedChild);
6263
});
6364

6465
});

src/ui/public/kuery/functions/__tests__/is.js

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import expect from 'expect.js';
22
import * as is from '../is';
33
import { nodeTypes } from '../../node_types';
4-
import _ from 'lodash';
54
import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
65
import ngMock from 'ng_mock';
6+
import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal';
77

88
let indexPattern;
99

@@ -54,34 +54,22 @@ describe('kuery functions', function () {
5454

5555
const node = nodeTypes.function.buildNode('is', '*', '*');
5656
const result = is.toElasticsearchQuery(node, indexPattern);
57-
expect(_.isEqual(expected, result)).to.be(true);
57+
expectDeepEqual(result, expected);
5858
});
5959

60-
it('should return an ES simple_query_string query in all fields mode when fieldName is "*"', function () {
60+
it('should return an ES multi_match query when fieldName is "*"', function () {
6161
const expected = {
62-
simple_query_string: {
63-
query: '"200"',
64-
all_fields: true,
62+
multi_match: {
63+
query: 200,
64+
fields: ['*'],
65+
type: 'phrase',
66+
lenient: true,
6567
}
6668
};
6769

6870
const node = nodeTypes.function.buildNode('is', '*', 200);
6971
const result = is.toElasticsearchQuery(node, indexPattern);
70-
expect(_.isEqual(expected, result)).to.be(true);
71-
});
72-
73-
// See discussion about kuery escaping for background:
74-
// https://github.com/elastic/kibana/pull/12624#issuecomment-312650307
75-
it('should ensure the simple_query_string query is wrapped in double quotes to force a phrase search', function () {
76-
const node = nodeTypes.function.buildNode('is', '*', '+response');
77-
const result = is.toElasticsearchQuery(node, indexPattern);
78-
expect(result.simple_query_string.query).to.be('"+response"');
79-
});
80-
81-
it('already double quoted phrases should not get wrapped a second time', function () {
82-
const node = nodeTypes.function.buildNode('is', '*', '"+response"');
83-
const result = is.toElasticsearchQuery(node, indexPattern);
84-
expect(result.simple_query_string.query).to.be('"+response"');
72+
expectDeepEqual(result, expected);
8573
});
8674

8775
it('should return an ES exists query when value is "*"', function () {
@@ -91,7 +79,7 @@ describe('kuery functions', function () {
9179

9280
const node = nodeTypes.function.buildNode('is', 'response', '*');
9381
const result = is.toElasticsearchQuery(node, indexPattern);
94-
expect(_.isEqual(expected, result)).to.be(true);
82+
expectDeepEqual(result, expected);
9583
});
9684

9785
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 () {
10391

10492
const node = nodeTypes.function.buildNode('is', 'response', 200);
10593
const result = is.toElasticsearchQuery(node, indexPattern);
106-
expect(_.isEqual(expected, result)).to.be(true);
94+
expectDeepEqual(result, expected);
10795
});
10896

10997
it('should support scripted fields', function () {

src/ui/public/kuery/functions/__tests__/not.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { nodeTypes } from '../../node_types';
44
import * as ast from '../../ast';
55
import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
66
import ngMock from 'ng_mock';
7+
import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal';
78

89
let indexPattern;
910

@@ -49,11 +50,11 @@ describe('kuery functions', function () {
4950

5051
it('should wrap a literal argument with an "is" function targeting all fields', function () {
5152
const literalFoo = nodeTypes.literal.buildNode('foo');
53+
const expectedChild = ast.toElasticsearchQuery(nodeTypes.function.buildNode('is', '*', 'foo'), indexPattern);
5254
const node = nodeTypes.function.buildNode('not', literalFoo);
5355
const result = not.toElasticsearchQuery(node, indexPattern);
5456
const resultChild = result.bool.must_not;
55-
expect(resultChild).to.have.property('simple_query_string');
56-
expect(resultChild.simple_query_string.all_fields).to.be(true);
57+
expectDeepEqual(resultChild, expectedChild);
5758
});
5859

5960
});

src/ui/public/kuery/functions/__tests__/or.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { nodeTypes } from '../../node_types';
44
import * as ast from '../../ast';
55
import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
66
import ngMock from 'ng_mock';
7+
import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal';
78

89
let indexPattern;
910

@@ -54,11 +55,11 @@ describe('kuery functions', function () {
5455

5556
it('should wrap a literal argument with an "is" function targeting all fields', function () {
5657
const literalFoo = nodeTypes.literal.buildNode('foo');
58+
const expectedChild = ast.toElasticsearchQuery(nodeTypes.function.buildNode('is', '*', 'foo'), indexPattern);
5759
const node = nodeTypes.function.buildNode('or', [literalFoo]);
5860
const result = or.toElasticsearchQuery(node, indexPattern);
5961
const resultChild = result.bool.should[0];
60-
expect(resultChild).to.have.property('simple_query_string');
61-
expect(resultChild.simple_query_string.all_fields).to.be(true);
62+
expectDeepEqual(resultChild, expectedChild);
6263
});
6364

6465
it('should require one of the clauses to match', function () {

src/ui/public/kuery/functions/is.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ export function toElasticsearchQuery(node, indexPattern) {
3333
return { match_all: {} };
3434
}
3535
else if (fieldName === '*' && value !== '*') {
36-
const userQuery = String(value);
37-
const query = isDoubleQuoted(userQuery) ? userQuery : `"${userQuery}"`;
38-
3936
return {
40-
simple_query_string: {
41-
query,
42-
all_fields: true
37+
multi_match: {
38+
query: value,
39+
fields: ['*'],
40+
type: 'phrase',
41+
lenient: true,
4342
}
4443
};
4544
}
@@ -68,8 +67,3 @@ export function toKueryExpression(node) {
6867

6968
return `${fieldName}:${value}`;
7069
}
71-
72-
function isDoubleQuoted(str) {
73-
return str.startsWith('"') && str.endsWith('"');
74-
}
75-

0 commit comments

Comments
 (0)