mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
(cherry picked from commit bc65bc5b56
)
Co-authored-by: Maryam Saeidi <maryam.saeidi@elastic.co>
This commit is contained in:
parent
8a3afc220b
commit
eac5a6a1af
3 changed files with 43 additions and 3 deletions
|
@ -166,3 +166,36 @@ Object {
|
|||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`buildEsQuery should generate correct es query for {"timeRange":{"from":"now-15min","to":"now"},"kuery":"kibana.alert.status: \\"recovered\\""} 1`] = `
|
||||
Object {
|
||||
"bool": Object {
|
||||
"filter": Array [
|
||||
Object {
|
||||
"bool": Object {
|
||||
"minimum_should_match": 1,
|
||||
"should": Array [
|
||||
Object {
|
||||
"match_phrase": Object {
|
||||
"kibana.alert.status": "recovered",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"range": Object {
|
||||
"@timestamp": Object {
|
||||
"format": "strict_date_optional_time",
|
||||
"gte": "now-15min",
|
||||
"lte": "now",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
"must": Array [],
|
||||
"must_not": Array [],
|
||||
"should": Array [],
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
|
|
@ -34,6 +34,13 @@ describe('buildEsQuery', () => {
|
|||
timeRange: defaultTimeRange,
|
||||
kuery: 'kibana.alert.status: "recovered" and kibana.alert.duration.us >= 120',
|
||||
},
|
||||
{
|
||||
timeRange: {
|
||||
from: 'now-15min',
|
||||
to: 'now',
|
||||
},
|
||||
kuery: 'kibana.alert.status: "recovered"',
|
||||
},
|
||||
];
|
||||
|
||||
test.each(testData)('should generate correct es query for %j', ({ kuery, timeRange }) => {
|
||||
|
|
|
@ -7,15 +7,15 @@
|
|||
|
||||
import { buildEsQuery as kbnBuildEsQuery, TimeRange } from '@kbn/es-query';
|
||||
import { TIMESTAMP } from '@kbn/rule-data-utils';
|
||||
import { getTime } from '@kbn/data-plugin/common';
|
||||
import { getRelativeTime } from '@kbn/data-plugin/common';
|
||||
|
||||
export function buildEsQuery(timeRange: TimeRange, kuery?: string) {
|
||||
const timeFilter =
|
||||
timeRange &&
|
||||
getTime(undefined, timeRange, {
|
||||
getRelativeTime(undefined, timeRange, {
|
||||
fieldName: TIMESTAMP,
|
||||
});
|
||||
const filtersToUse = [...(timeFilter ? [timeFilter] : [])];
|
||||
const filtersToUse = timeFilter ? [timeFilter] : [];
|
||||
const queryToUse = kuery ? { query: kuery, language: 'kuery' } : [];
|
||||
|
||||
return kbnBuildEsQuery(undefined, queryToUse, filtersToUse);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue