我有一个场景,在elastic search查询中,在应该子句中,我需要有一个必须子句。
例如,我需要以这样一种方式过滤数据,即如果数据只应该来自仅具有分派区id为10的订单和仅具有运营商id为1,2,3的订单,但也应该拉取具有驱动器id为1,2,3的所有订单的数据。
在我当前场景中,如果运营商id 1具有调度区域id为9,则其拉取所有运营商id为1、2、3和分派区id为10的数据,并且还拉取不是10 .i.e的分派区,该数据也将到来。
如何在应该查询中添加一个必须子句。
{
"from": 0,
"size": 10000,
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
[
{
"terms": {
"dispatchAreaId": [
10
]
}
},
{
"terms": {
"carrierId": [
1,2,3
]
}
},
{
"terms": {
"driverIds": [
1,2,3
]
}
}
]
]
}
}
]
}
}
}发布于 2019-08-30 19:49:21
在下面尝试查询
{
"from": 0,
"size": 10000,
"query": {
"bool": {
"should": [
{
"terms": {
"dispatchAreaId": [
10
]
}
},
{
"bool": {
"must": [
{
"terms": {
"dispatchAreaId": [
10
]
}
},
{
"terms": {
"carrierId": [
1,
2,
3
]
}
}
]
}
}
],
"minimum_should_match": 1
}
}
}希望这能有所帮助!!
https://stackoverflow.com/questions/57726104
复制相似问题