我有一个场景,在弹性搜索查询的should子句中,我需要一个must子句。
例如,我需要以一种方式过滤数据:如果数据仅应针对调度区域ID仅为10且承运人ID仅作为1,2,3的订单,但也应为所有具有驾驶员ID的订单提取数据为1,2,3。
在我当前的情况下,它针对所有运营商ID的提取数据为1,2,3,调度区域ID为10,调度区域ID也不为10。即,如果运营商ID 1的调度区域ID为9,则该数据也是未来。
如何在应查询中添加must子句。
+----------+------+--------+--+---------------+-------+------------+--+--------+--------+-----------------------------+
| stat_atp | | | | tblTourns_atp | | | | Output | | |
+----------+------+--------+--+---------------+-------+------------+--+--------+--------+-----------------------------+
| ID_T | FS_1 | FSOF_1 | | ID_T | ID_Ti | DATE | | ID_T | OUTPUT | Rationale |
| 1 | 20 | 40 | | 1 | 1 | 01/01/2019 | | 1 | 50% | ID_T "1" |
| 2 | 30 | 100 | | 2 | 1 | 05/01/2019 | | 2 | 31% | ID_T "1" & "2" & "3" |
| 3 | 40 | 150 | | 3 | 1 | 03/01/2019 | | 3 | 32% | ID_T "1" & "3" |
| 4 | 30 | 100 | | 4 | 2 | 04/01/2019 | | 4 | 30% | ID_T "4" |
| 5 | 30 | 100 | | 5 | 2 | 05/01/2019 | | 5 | 30% | ID_T "4" & "5" |
| 6 | 40 | 150 | | 6 | 2 | 06/01/2019 | | 6 | 29% | ID_T "4" & "5" & "6" |
| 7 | 20 | 40 | | 7 | 3 | 01/01/2019 | | 7 | 50% | ID_T "7" |
| 8 | 30 | 100 | | 8 | 3 | 08/01/2019 | | 8 | 35% | ID_T "7" & "8" & "9" & "10" |
| 9 | 40 | 150 | | 9 | 3 | 02/01/2019 | | 9 | 32% | ID_T "7" & "9" |
| 10 | 20 | 40 | | 10 | 3 | 06/01/2019 | | 10 | 39% | ID_T "7" & "9" & "10" |
+----------+------+--------+--+---------------+-------+------------+--+--------+--------+-----------------------------+
答案 0 :(得分:1)
尝试以下查询
{
"from": 0,
"size": 10000,
"query": {
"bool": {
"should": [
{
"terms": {
"dispatchAreaId": [
10
]
}
},
{
"bool": {
"must": [
{
"terms": {
"dispatchAreaId": [
10
]
}
},
{
"terms": {
"carrierId": [
1,
2,
3
]
}
}
]
}
}
],
"minimum_should_match": 1
}
}
}
希望这会有所帮助!