elasticsearch - ElasticSearch bool 查询结合 should 和 filter
问题描述
在elasticsearch你知道为什么
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
conditions1
]
}
},
{
"bool": {
"must": [
conditions2
]
}
}
],
"filter": [
conditions3
]
}
}
}
如果条件 3 为真,即使条件 2 和条件 1 为假,也总能找到文档
解决方案
根据https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html上的文档:
如果 bool 查询在查询上下文中并且有一个 must 或 filter 子句,那么即使所有 should 查询都不匹配,文档也会匹配 bool 查询。在这种情况下,这些子句仅用于影响分数。如果 bool 查询是一个过滤上下文或者既没有 must 也没有 filter,那么至少一个 should 查询必须匹配一个文档才能匹配 bool 查询。此行为可以通过设置 minimum_should_match 参数来显式控制。
推荐阅读
- python - 使用 Python FFMPEG 在模板/布局中合并多个视频?
- telegram - 如何使用 Telethon 删除消息中的 reply_keyboard?
- spring-boot - 春季启动应用程序优雅关闭期间的KafkaProducer InterruptedException
- flutter - Flutter 手势识别器中的辅助按钮/点击是什么?
- excel - 尝试将范围加载到变体数组中时溢出
- algorithm - 线性函数的 O 表示法有无数个解?
- python - 将闭合曲线拟合到一组噪声点
- objective-c - 在 Objective C 中清理 NSURL
- python - Flask-SQLAlchemy:SAWarning:身份映射已经有(对象)的身份,用新刷新的对象替换它
- ansible - 如果嵌套列表中的 var 在 Ansible 中为真,则执行任务