【发布时间】:2020-07-28 00:21:10
【问题描述】:
我想要过去 24 小时的所有记录。如果我使用日期数学(现在),我不会得到任何记录。如果我手动指定日期,我会得到记录,但有些是几天前的。
示例记录:
"_index": "platform-862a:logs-001386",
"_type": "doc",
"_id": "Ihg0enMBqxITPs13KML0",
"_score": 20.144087,
"_source": {
"@timestamp": "2020-07-23T05:45:04.893Z",
"timeMillis": 1595819172661,
"application": "an app name",
"message": "an error message"
}
编辑:在上面的示例中添加了timeMillis 字段。原来是答案的关键。
查询:
{
"_source": [
"@timestamp",
"timeMillis",
"application",
"message"
],
"query": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"format": "yyyy-MM-dd'T'HH:mm:ss'Z'",
"gte": "2020-07-26T00:00:00Z"
}
}
},
{
"term": {
"level": "ERROR"
}
},
{
"term": {
"environment": "prod"
}
}
],
"should": [
{
"match_phrase": {
"application": "app1"
}
},
{
"match_phrase": {
"application": "app12"
}
}
],
"minimum_should_match": 1
}
}
}
我正在通过 Postman 发送查询。我在 CDT,日志是由 UTC 的服务器编写的。我认为这可能是问题所在,但我看到的是几天前 2020 年 7 月 23 日的记录。
如果我将范围更改为:
"@timestamp": {
"gte": "now-2d"
}
我没有得到任何记录 (hits.total=0)。
我尝试过指定或不指定时区、日期格式、lt 日期、在过滤器块内等,但在过去的 24 小时内没有任何东西能吸引我。我试过不使用 should 块并删除所有其他 must 块。
而我想要的格式 now-1d 根本不返回任何内容。
【问题讨论】:
-
你能分享你索引的映射吗?
-
抱歉,我不确定这是什么意思。我是 elasticsearch 新手,日志记录/Kibana 基础架构归公司基础架构团队所有。
-
你能用运行
GET platform-862a:logs-001386得到的结果更新你的问题吗?
标签: elasticsearch