我需要过滤ES查询,其中日期字段的值是LTE给定值或该字段完全丢失。这是我此时的查询:
{
"from":0,
"size":50,
"query":{
"bool":{
"filter":[
{
"term":{
"corpusid.string.as_is":"42:6:4"
}
},
{
"nested":{
"path":"category.object",
"query":{
"bool":{
"must":[
{
"bool":{
"should":[
{
"range":{
"category.object.startdate":{
"lte":"2021-03-09T19:32:11.316Z"
}
}
},
{
"must_not":[
{
"exists":{
"field":"category.object.startdate"
}
}
]
}
]
}
}
]
}
}
}
}
]
}
}
}
提交该查询时,出现错误“[must_not]查询格式错误,查询名称后没有start_object”。万一重要,我们正在运行ElasticSearch版本5.3.1。
最佳答案
我对查询进行了重构。删除了必须,为must_not添加了bool。
{
"from":0,
"size":50,
"query":{
"bool":{
"filter":[
{
"term":{
"corpusid.string.as_is":"42:6:4"
}
},
{
"nested":{
"path":"category.object",
"query":{
"bool":{
"should": [
{
"range":{
"category.object.startdate":{
"lte":"2021-03-09T19:32:11.316Z"
}
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "category.object.startdate"
}
}
}
}
]
}
}
}
}
]
}
}
}
关于elasticsearch - 过滤日期值是给定值或缺少值的ElasticSearch查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49203077/