mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[KQL] Use term queries for keyword fields (#143599)
This commit is contained in:
parent
04075a1c51
commit
511f95a16a
2 changed files with 20 additions and 2 deletions
|
@ -361,6 +361,23 @@ describe('kuery functions', () => {
|
|||
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
test('should use a term query for keyword fields', () => {
|
||||
const node = nodeTypes.function.buildNode('is', 'machine.os.keyword', 'Win 7');
|
||||
const result = is.toElasticsearchQuery(node, indexPattern);
|
||||
expect(result).toEqual({
|
||||
bool: {
|
||||
should: [
|
||||
{
|
||||
term: {
|
||||
'machine.os.keyword': 'Win 7',
|
||||
},
|
||||
},
|
||||
],
|
||||
minimum_should_match: 1,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -100,6 +100,7 @@ export function toElasticsearchQuery(
|
|||
}
|
||||
|
||||
const queries = fields!.reduce((accumulator: any, field: DataViewFieldBase) => {
|
||||
const isKeywordField = field.esTypes?.length === 1 && field.esTypes.includes('keyword');
|
||||
const wrapWithNestedQuery = (query: any) => {
|
||||
// Wildcards can easily include nested and non-nested fields. There isn't a good way to let
|
||||
// users handle this themselves so we automatically add nested queries in this scenario.
|
||||
|
@ -142,7 +143,7 @@ export function toElasticsearchQuery(
|
|||
}),
|
||||
];
|
||||
} else if (wildcard.isNode(valueArg)) {
|
||||
const query = field.esTypes?.includes('keyword')
|
||||
const query = isKeywordField
|
||||
? {
|
||||
wildcard: {
|
||||
[field.name]: value,
|
||||
|
@ -177,7 +178,7 @@ export function toElasticsearchQuery(
|
|||
}),
|
||||
];
|
||||
} else {
|
||||
const queryType = type === 'phrase' ? 'match_phrase' : 'match';
|
||||
const queryType = isKeywordField ? 'term' : type === 'phrase' ? 'match_phrase' : 'match';
|
||||
return [
|
||||
...accumulator,
|
||||
wrapWithNestedQuery({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue