Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch Elasticsearch应与must_not-非嵌套匹配_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Aws Elasticsearch - Fatal编程技术网 elasticsearch Elasticsearch应与must_not-非嵌套匹配,elasticsearch,aws-elasticsearch,elasticsearch,Aws Elasticsearch" /> elasticsearch Elasticsearch应与must_not-非嵌套匹配,elasticsearch,aws-elasticsearch,elasticsearch,Aws Elasticsearch" />

elasticsearch Elasticsearch应与must_not-非嵌套匹配

elasticsearch Elasticsearch应与must_not-非嵌套匹配,elasticsearch,aws-elasticsearch,elasticsearch,Aws Elasticsearch,刚接触Elasticsearch,正在开发一个我不愿改变的遗留模型。我有一个日期字段,如果它的值为null(我想是因为ES处理0000-00-00)的方式,我们就不会输入它。我希望能够查询具有特定日期或字段不存在的数据。以下是我所拥有的: { "size": 10000, "query": { "bool": { "must": [

刚接触Elasticsearch,正在开发一个我不愿改变的遗留模型。我有一个日期字段,如果它的值为
null
(我想是因为ES处理
0000-00-00
)的方式,我们就不会输入它。我希望能够查询具有特定日期或字段不存在的数据。以下是我所拥有的:

{
    "size": 10000,
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "AccountID": "xxxx"
                    }
                },
                {
                    "term": {
                        "LocationID": "xxxx"
                    }
                },
                {
                    "should": [
                        {
                            "range": {
                                "CloseDate": {
                                    "gte": "2020-11-01",
                                    "lte": "2020-12-02"
                                }
                            }
                        },
                        {
                            "bool": {
                                "must_not": {
                                    "exists": {
                                        "field": "CloseDate"
                                    }
                                }
                            }
                        }
                    ]
                }
            ]
        }
    }
}

尝试此操作时,
[should]查询格式错误,查询名称后没有start\u对象。是否有其他语法或确实存在格式错误?

错误清楚地表明您的查询格式不正确。您缺少一个
]
括号。请尝试此查询:

{
  "size": 10000,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "AccountID": "xxxx"
          }
        },
        {
          "term": {
            "LocationID": "xxxx"
          }
        }
      ],                                   <-- note this
      "should": [
        {
          "range": {
            "CloseDate": {
              "gte": "2020-11-01",
              "lte": "2020-12-02"
            }
          }
        },
        {
          "bool": {
            "must_not": {
              "exists": {
                "field": "CloseDate"
              }
            }
          }
        }
      ]
    }
  }
}
{
“大小”:10000,
“查询”:{
“布尔”:{
“必须”:[
{
“期限”:{
“帐户ID”:“xxxx”
}
},
{
“期限”:{
“位置ID”:“xxxx”
}
}

],A
must
子句可以在
[]
内有多个查询。请注意,
should
也是
bool
查询的子句,而不是查询本身。因此,它应该在
bool

{
  "size": 10000,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "AccountID": "xxxx"
          }
        },
        {
          "term": {
            "LocationID": "xxxx"
          }
        },
        {
          "bool": {            <------------- Note this
            "should": [
              {
                "range": {
                  "CloseDate": {
                    "gte": "2020-11-01",
                    "lte": "2020-12-02"
                  }
                }
              },
              {
                "bool": {
                  "must_not": {
                    "exists": {
                      "field": "CloseDate"
                    }
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}
{
“大小”:10000,
“查询”:{
“布尔”:{
“必须”:[
{
“期限”:{
“帐户ID”:“xxxx”
}
},
{
“期限”:{
“位置ID”:“xxxx”
}
},
{

“布尔”:{另外,请注意这是elasticsearch 6。3@TylerChristian您是否有机会查看我的答案,期待您的反馈?我找不到缺少括号的地方。VScode确认没有json错误。不确定您看到了什么。@TylerChristian当您运行与问题相同的查询时,您将得到错误
[should]查询格式不正确,在查询名称后没有start\u对象,但它不是缺少的括号。它是有效的JSON。我在代码中有一个步骤是
JSON。stringify
首先会失败。但是感谢您花时间查看它。@TylerChristian因为我不知道您的用例,所以我认为您需要
 must
子句和
should
子句分开。这就是为什么我在
must
子句末尾添加了一个
]