【发布时间】:2017-08-25 20:04:03
【问题描述】:
我正在尝试在 Elasticsearch 中使用日期数学进行日期范围查询,但它没有返回任何结果:
`query: {
bool: {
must: {
query_string: {
query: "created_at:[now-1m/d TO now/d+1d]", default_operator: "AND", analyzer: "my_text"}
}
}
}
}`
更改查询以包含实际日期确实有效:“created_at:[2017-07-25 TO 2017-08-25]”
我还尝试了一种解决方法,将 query_string 与范围查询结合使用,但也没有返回任何结果:
`query: {
bool: {
must: [
{query_string: {query: "", default_operator: "AND", analyzer: "my_text"}},
{range: {"created_at"=>{from: "now-1m/d", to: "now/d+1d"}}}]
}
}
}`
使用日期数学确实可以在 aggs 中显示正确的计数:
`aggs: {
created_at: {
date_range: {
field: "created_at", keyed: true, ranges: [
{from: "now/d", to: "now/d+1d", key: "Today"},
{from: "now-1d/d", to: "now/d+1d", key: "In the last day"},
{from: "now-7d/d", to: "now/d+1d", key: "In the last week"},
{from: "now-1M/d", to: "now/d+1d", key: "In the last month"}
]
}
}
}`
日期数学是否适用于 Elasticsearch query_string 查询?如果不是,那么正确的解决方法是什么?
【问题讨论】:
标签: elasticsearch elasticsearch-5