elasticsearch - 用于过滤的 Elasticsearch DSL bool 查询
问题描述
我有一个 Elasticsearch DSL 查询如下
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"api": "A"
}
},
{
"match_phrase": {
"api": "B"
}
},
{
"match_phrase": {
"api": "C"
}
}
],
"minimum_should_match": 1
}
}
}
据我了解,这就像
匹配 if (api = A 或 api = B 或 api = C)
我想在第三次检查中添加另一个检查不同字段的条件。
例如 match if (api = A or api = B or (api = C and another_field = D) ) 知道怎么做吗?
解决方案
您可以使用组合bool/must
查询
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"api": "A"
}
},
{
"match_phrase": {
"api": "B"
}
},
{
"bool": {
"must": [
{
"match_phrase": {
"api": "C"
}
},
{
"match_phrase": {
"another_field": "D"
}
}
]
}
}
],
"minimum_should_match": 1
}
}
}
推荐阅读
- php - Symfony DI:未捕获的 ArgumentCountError:函数 App::__construct() 的参数太少,第 28 行的 index.php 中传递了 0,而预期的正是 1
- javascript - 是否可以在 AngularJS 中模拟按键?
- mysql - 如何根据记录的前缀自动增加 char 数据类型?
- r - R/Shiny:从服务器上的文件夹下载多个文件 (zip)
- angular - 在 vs 代码中使用 Angular 控制台插件
- java - 在 Fragments 中使用 Volley 填充 RecyclerView
- java - 不能在 Spring Boot 中使用 @Async
- docker - 为什么文件在 /var/lib/docker/volumes/
/_data/ 在 docker 容器中不可见? - sql - 相交上的平均值
- android - 如何在服务中使用离子库?