簡體   English   中英

Elastic Search - 多重匹配條件

[英]Elastic Search - Multiple match condition

我需要編寫一個復雜的場景並想知道該怎么做——我有 3 種不同類型的條目,如下所示

我需要找到帶有 **completed ** 的呼叫狀態,但有些情況下 completed 狀態存儲在 2 個條目中。

Record-1 [ Condition-1: 當 lastOutboundStatus 繁忙且 lastInbountStatus 完成時]

注意:lastOutboundStatus 應該是 busy | 它可以是其他狀態,也可以是無人接聽、拒絕

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

Record-2 [條件2:當lastInbountStatus完成且lastOutboundStatus不存在時]

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

Record-3 [ 條件 3:當 lastOutboundStatus 完成時,“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"
          }
        }
      ]
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM