我有一个如下的 Elasticsearch DSL 查询
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"api": "A"
}
},
{
"match_phrase": {
"api": "B"
}
},
{
"match_phrase": {
"api": "C"
}
}
],
"minimum_should_match": 1
}
}
}
据我所知,这类似于
匹配 if (api = A or api = B or api = C)
我想在第三个检查中添加另一个检查不同字段的条件。
例如匹配 if (api = A or api = B or (api = C and another_field = D ) ) 知道怎么做吗?
答案 0 :(得分:1)
您可以组合使用 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
}
}
}