mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Remove simple_query_string hack now that multi_match supports * (#13285)
This commit is contained in:
parent
3e3b0cb8ba
commit
3dfcf5dc98
5 changed files with 25 additions and 40 deletions
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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('"');
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue