elasticsearch - Elasticsearch 应该使用 must_not - 非嵌套
问题描述
刚接触 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] query malformed, no start_object after query name
我在尝试这个时得到了错误。是否有替代语法或确实格式错误?
解决方案
一个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"
}
}
}
}
]
}
}
]
}
}
}
推荐阅读
- django - 创建将更改模型中的 BooleanField 的 Django HTML 按钮
- python - Django和docker中.env文件中的环境变量
- algorithm - N个移动点之间的最短距离
- java - 如何在java中创建具有不同语言名称的目录?
- html - 文章与部分。在这种情况下应该使用哪一个?
- reactjs - Reactjs路由css问题
- azure - 带有两个 csv 文件的 Azure terraform 参数不起作用
- python - 在没有库的情况下计算 ROC 的不同阈值
- excel - 将 excel 中的名称与中间名和额外空格匹配
- c++ - 即使我添加了 Tools -> Debugging 的设置,.pdb 符号也不会加载