gpt4 book ai didi

elasticsearch - 将 elasticsearch 日期范围查询与空值结合起来

转载 作者:行者123 更新时间:2023-11-29 02:44:27 25 4
gpt4 key购买 nike

我想使用如下日期范围查询:

{
"range" : {
"deadline" : {
"gte" : "2016-12-14",
}
}
}

我的索引也包含截止日期的空值。我想在搜索结果中获取那些日期为空的文档以及范围内的日期。如何将日期范围与弹性 5.x 中的“must_not”存在查询结合起来

最佳答案

我认为 bool 查询 可以解决问题。

{
"query": {
"bool": {
"should": [
{
"range": {
"deadline": {
"gte": "2016-12-14"
}
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "deadline"
}
}
}
}
]
}
}
}

在 Elasticsearch 索引中,null 值不存在,因此我们使用 exist 查询。使用缺少的查询会不那么冗长,但它是 deprecated since 2.2 .

我没有足够的信息,所以我的示例在查询上下文中运行,但在这种情况下,过滤上下文可能会更方便。

关于elasticsearch - 将 elasticsearch 日期范围查询与空值结合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41139525/

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