我正在使用 flex 搜索版本1.7.5
我从这篇文章中汲取了一些想法:
Elastic search Not filter inside and filter
以下查询似乎并未过滤出与item_category_id
17相关的项。是否存在语法错误?在not
数组之外,在filters
数组内部定义的术语可以正常工作。
{
query: {
filtered: {
filter: {
and: {
filters: [
{ not: {
filter: {
terms: {item_category_ids: [17] }
}
}
},
{ term: { user_inactive: false } },
{ term: { kind: 1 } }
]
}
}
}
}
最佳答案
在ES 2.0中, filtered
and and/not
queries have been deprecated应该改为使用bool/filter/must_not
:
{
"query": {
"bool": {
"filter": [
{
"bool": {
"must_not": {
"terms": {
"item_category_ids": [
17
]
}
}
}
},
{
"term": {
"user_inactive": false
}
},
{
"term": {
"kind": 1
}
}
]
}
}
}
对于ES 1.7,您需要将查询更改为此:
{
"query": {
"constant_score": {
"filter": {
"bool": {
"must_not": {
"terms": {
"item_category_ids": [
17
]
}
},
"must": [
{
"term": {
"user_inactive": false
}
},
{
"term": {
"kind": 1
}
}
]
}
}
}
}
}
关于ruby-on-rails - 如何实现 Elasticsearch 不过滤?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41133067/