elasticsearch - elasticsearch date range 获取今天和昨天之间的日期范围
问题描述
我正在使用弹性搜索,我正在尝试从前一天的任何第二个 10:am到 10:am the present-day获取报告。请帮忙,谢谢。
我试过这个:
"@timestamp":{
"gte": "now-1d/d+10h",
"lt": "now/d+10h"
解决方案
您需要@timestamp
根据您使用的数据格式设置字段的映射。你可以参考这个官方文档来了解更多关于日期字段类型的信息。
添加带有索引数据、映射、搜索查询和搜索结果的工作示例
索引映射:
{
"mappings": {
"properties": {
"@timestamp": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}
}
指数数据:
{
"@timestamp": "2021-05-04 10:11:51"
}
{
"@timestamp": "2021-05-04 09:11:51"
}
{
"@timestamp": "2021-05-05 09:11:51"
}
{
"@timestamp": "2022-05-05 09:11:51"
}
搜索查询:
{
"query": {
"range": {
"@timestamp": {
"gte": "now-1d/d+10h",
"lt": "now/d+10h"
}
}
}
}
搜索结果:
"hits": [
{
"_index": "67392888",
"_type": "_doc",
"_id": "2",
"_score": 1.0,
"_source": {
"@timestamp": "2021-05-05 09:11:51"
}
},
{
"_index": "67392888",
"_type": "_doc",
"_id": "4",
"_score": 1.0,
"_source": {
"@timestamp": "2021-05-04 10:11:51"
}
}
]
推荐阅读
- http - 图片中的http响应消息有什么问题?
- asp.net - .net 核心客户绑定中的 wcf
- html - 如何在没有 CSS 的情况下在 HTML 中显示同一行徽标和标题?
- sql - 满足条件时按字段分组
- performance - 如何加快 txt 文件在 R 中追加的速度
- turing-machines - jflap 复制状态或转换
- javascript - 使用 JavaScript 将输入值和图像移动到另一个页面
- python - 将迭代重写为具有多个输入 pandas 的 .apply 函数
- twitter-bootstrap - 检查没有 jQuery 的 bootstrap-5
- mysql - 加入 2 个表给出空结果