【发布时间】:2018-10-09 18:00:17
【问题描述】:
我的弹性搜索索引具有嵌套字段。我想使用 must,其中包含一个 must_not 查询和一个嵌套查询。我已经通过以下方式单独尝试了 must_not 查询:
{
"bool": {
"must_not": [{
"nested": {
"path": "fields",
"query": {
"terms": {
"fields.value.raw": [
"200"
]
}
}
}
}]
}
}
上面的查询给了我一个有效的结果,但是当我用必须查询尝试这个时,它不会给我任何结果。我正在使用以下查询:
{
"bool": {
"must": [{
"nested": {
"path": "fields",
"query": {
"bool": {
"must": [{
"match": {
"fields.uid": "number"
}
}, {
"bool": {
"must_not": [{
"nested": {
"path": "fields",
"query": {
"terms": {
"fields.value.raw": [
"200"
]
}
}
}
}]
}
}]
}
}
}
}]
}
}
上面的查询没有给我一个有效的结果。上面的查询有什么问题? 如何在嵌套查询中使用 must_not?
【问题讨论】:
-
如果您写一两句话来描述您希望查询执行的操作会有所帮助。例如,我想要所有价格等于 10 的文档。
-
我的嵌套模式如下: { "fields": { "type": "nested", "properties": { "uid": { "type": "keyword" }, "value" : { "type": "text", "fields": { "raw": { "type": "keyword" } } } } } } 所以我想要具有字段的文档。uid 是数字字段的数字和值(fields.value) 不包含“200”所以需要在must中添加must_not,如何才能得到有效结果?
标签: elasticsearch