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:
parent
19e18ef121
commit
4b132d475f
2 changed files with 20 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue