我想查询我的elasticsearch(使用python库)并且我想过滤一些文档。由于我不想获得分数,因此我仅使用过滤器,而不能使用关键字:
{
"_source": ["entities"],
"query": {
"bool": {
"must_not": [
{"exists": {"field": "retweeted_status"}}
],
"filter": [
{"match": {"entities.urls.display_url": "blabla.com"}},
{"match": {"entities.urls.display_url": "blibli.com"}}]
}
}
}
这是我所做的查询,但问题是在同一个过滤器中,它显然是执行的 AND
操作。我希望它是一个 OR。如何更改查询以获取包含“blibli.com”或“blabla.com”的所有文档
最佳答案
您可以将 bool
嵌套在另一个 bool
中,这样您就可以编写如下查询:
{
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "retweeted_status"
}
}
],
"filter": [
{
"bool": {
"should": [
{
"match": {
"entities.urls.display_url": "blabla.com"
}
},
{
"match": {
"entities.urls.display_url": "blibli.com"
}
}
]
}
}
]
}
}
}
在ES 5.3上测试,可以使用Explain API检查这是否也适用于您的 Elasticsearch 版本。
关于python - 或者在 Elasticsearch 过滤器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43041271/