I am trying to use date math in my query without success.
When I paste a KQL query on the web explorer's address bar I got a successful result with an example like this:
- base url + time:(from:'2023-10-06T20:44:13.558Z',to:'2023-10-06T20:44:13.558Z')) + more parameters
but I want to subtract 1 Hour in the from parameter so I tried KQL queries like the following without success:
-
base url + time:(from:'2023-10-06T20:44:13.558\|\|-1H',to:'2023-10-06T20:44:13.558Z')) + more parameters
-
base url + time:(from:'2023-10-06T20:44:13.558||-1H',to:'2023-10-06T20:44:13.558Z')) + more parameters
-
base url + time:(from:'2023-10-06T20:44:13.558Z%5C%7C%5C%7C-1H',to:'2023-10-06T20:44:13.558Z')) + more parameters
I also tried a DSL Query like this succesfully:
"query": {
"bool": {
"must": [],
"filter": [
{
"bool": {
"should": [
{
"term": {
"level.keyword": "Error"
}
}
],
"minimum_should_match": 1
}
},
{
"range": {
"@timestamp": {
"format": "strict_date_optional_time",
"gte": "2023-10-06T20:44:13.558Z||-1H",
"lte": "2023-10-06T20:44:13.558Z"
}
}
}
],
"should": [],
"must_not": []
}
},
but I need the KQL not the DSL query.
Note: The goal for all this is to be able to send a email via the body of elastic alerts/rules which points to the specific errors the rule found .