弹性搜索—多个匹配条件



我需要写一个复杂的场景,想知道如何做到这一点我有三个不同类型的条目如下

我需要找到呼叫状态与**完成**,但有情况下,状态与完成存储在2个条目。

Record-1 [Condition-1: when lastOutboundStatus is busy and lastInbountStatus is completed]

注意:lastOutboundStatus应该是busy |也可以是其他状态,如no-answer, rejected

"lastOutboundStatus": {
"status": "busy",
"timeStamp": 1664945413238
},
"lastInboundStatus": {
"status": "completed",
"timeStamp": 1664945413238
},

Record-2 [Condition-2: when lastInbountStatus is completed and lastOutboundStatus不存在]

"lastInboundStatus": {
"status": "completed",
"timeStamp": 1664945413238
}

Record-3 [Condition-3: when lastOutboundStatus is completed, and "lastInboundStatus"存在或不存在,不重要-优先级是lastOutboundStatus是否完成]

"lastOutboundStatus": {
"status": "completed",
"timeStamp": 1664945413238
}
"lastInboundStatus": {
"status": "completed",
"timeStamp": 1664945413238
},

只有一个单一的查询,我需要容纳3个条件-以便适当的记录会来。所以当我搜索状态完成时,以上3条记录都应该出现。

任何忍者都可以帮忙!!!!

我是elasticsearch的新手,需要一些大师的帮助

您可以使用以下OR查询:

POST test/_search
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"filter": [
{
"term": {
"lastInboundStatus.status": "completed"
}
},
{
"terms": {
"lastOutboundStatus.status": [
"busy",
"other-status"
]
}
}
]
}
},
{
"bool": {
"filter": [
{
"term": {
"lastInboundStatus.status": "completed"
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "lastOutboundStatus.status"
}
}
}
}
]
}
},
{
"term": {
"lastOutboundStatus.status": "completed"
}
}
]
}
}
}

最新更新