Skip to content

Commit

Permalink
Fix Wildcard Queries Against The Default Field (elastic#24778)
Browse files Browse the repository at this point in the history
When querying against the default field (i.e. querying without specifying a field) we weren't correctly handling values with wildcards in them.
  • Loading branch information
Bargs committed Oct 30, 2018
1 parent efeca31 commit 7b15049
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ui/public/kuery/functions/__tests__/is.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/ui/public/kuery/functions/is.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7b15049

Please sign in to comment.