Fix Wildcard Queries Against The Default Field (#24778)

When querying against the default field (i.e. querying without specifying a field) we weren't correctly handling values with wildcards in them.
This commit is contained in:
Matt Bargar 2018-10-30 15:22:51 -04:00 committed by GitHub
parent 19e18ef121
commit 4b132d475f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -96,6 +96,18 @@ describe('kuery functions', function () {
expectDeepEqual(result, expected);
});
it('should return an ES query_string query using default_field when fieldName is null and value contains a wildcard', function () {
const expected = {
query_string: {
query: 'jpg*',
}
};
const node = nodeTypes.function.buildNode('is', null, 'jpg*');
const result = is.toElasticsearchQuery(node, indexPattern);
expectDeepEqual(result, expected);
});
it('should return an ES bool query with a sub-query for each field when fieldName is "*"', function () {
const node = nodeTypes.function.buildNode('is', '*', 200);
const result = is.toElasticsearchQuery(node, indexPattern);

View file

@ -48,6 +48,14 @@ export function toElasticsearchQuery(node, indexPattern) {
const type = isPhraseArg.value ? 'phrase' : 'best_fields';
if (fieldNameArg.value === null) {
if (valueArg.type === 'wildcard') {
return {
query_string: {
query: wildcard.toQueryStringQuery(valueArg),
},
};
}
return {
multi_match: {
type,