我有一组文章。我想过滤tags
和host
。
例如,我希望所有标有“新闻”或“体育”并且“主机”设置为“cnn.com”或“bbc.com”的文章。
我试图创建此嵌套的 bool(boolean) 过滤器,但这没有用。它还返回其他主机的文章。
有什么建议么?
GET _search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"should": [
// Match one or more of these tags.
{ "term" : { "tags" : "sport"} },
{ "term" : { "tags" : "news"} },
{ "bool": {
// Only from one of these hosts.
"should": [
{ "term": { "host": "bbc.com" } },
{ "term": { "host": "cnn.com" } }
]
}}
]
}
}
}
}
}
最佳答案
像这样嵌套查询是可行的。 :-)
GET _search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{ "bool": {
"should": [
{ "term" : { "tags" : "sport"} },
{ "term" : { "tags" : "news"} }
]
}},
{ "bool": {
"should": [
{ "term": { "host": "bbc.com" } },
{ "term": { "host": "cnn.com" } }
]
}}
]
}
}
}
}
}
关于elasticsearch - 如何在Elasticsearch中使用嵌套过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32202793/