将弹性搜索日期范围查询与空值相结合 [英] Combine elasticsearch date range queries with null values
问题描述
我想使用如下所示的日期范围查询:
I would like to use date range query like the following :
{
"range" : {
"deadline" : {
"gte" : "2016-12-14",
}
}
}
我的索引还包含截止期限的空值。我想在搜索结果中将这些无效的日期文档以及范围内的日期。如何将日期范围与弹性5.x中的must_not存在查询相结合
My index contains empty values for deadline as well. I would like to get those null dated documents in search results along with the dates in range. How can I combine date range with "must_not" exist query in elastic 5.x
推荐答案
我认为一个查询
{
"query": {
"bool": {
"should": [
{
"range": {
"deadline": {
"gte": "2016-12-14"
}
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "deadline"
}
}
}
}
]
}
}
}
在弹性搜索索引中,值不存在,所以我们使用存在查询。使用缺少的查询将不太冗长,但它是自2.2以后弃用
In Elasticsearch indexes null values don't exist, so we use the exist query. Using the missing query would been less verbose, but it's deprecated since 2.2.
我没有足够的信息,所以我的示例在查询上下文中运行, em>过滤器上下文在这种情况下会更方便。
I don't have enough information so my example runs in query context, but maybe filter context would be more convenient in this case.
这篇关于将弹性搜索日期范围查询与空值相结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!