gpt4 book ai didi

带日期数学的 Elasticsearch query_string

转载 作者:行者123 更新时间:2023-12-02 22:29:46 24 4
gpt4 key购买 nike

我正在尝试在 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 查询?如果不是,正确的解决方法是什么?

最佳答案

我认为你有一个大写拼写错误 -- m 应该是 M:[now-1M/d TO now/d+1d](在你的最后一个例子中大写是正确的,这就是它在那里工作的原因)。

关于带日期数学的 Elasticsearch query_string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45888679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com