簡體   English   中英

Elasticsearch嵌套查詢以獲取閾值

[英]Elasticsearch nested query for getting threshold hit

我有嵌套的索引結構,如下所示:

{
   "customersData": {
      "mappings": {
         "type1": {
            "properties": {
               "md5": {
                  "type": "string"
               },
               "uscan": {
                  "properties": {
                     "ibm": {
                        "properties": {
                           "found": {
                              "type": "boolean"
                           }
                        }
                     },
                      "google": {
                        "properties": {
                           "found": {
                              "type": "boolean"
                           }
                        }
                     },
                      "ebay": {
                        "properties": {
                           "found": {
                              "type": "boolean"
                           }
                        }
                     } 
                     ...
                    }
                },
               "plink":{"type":"string"}
            }
        }
     }
   }
}

示例數據如下: uscan.ebay.found:true,uscan.ibm.found:true,uscan.google.found:false,...

每個記錄可能有一百個客戶,我想查詢found = true大於5(每個記錄至少有5個客戶found = true)。 任何想法,謝謝!

您可以為此使用minimum_should_match來指定應該匹配的should子句中的最小條件數。 使用以下查詢:

{
  "query": {
    "bool": {
      "should": [
        {
          "term": {
            "uscan.ibm.found": true
          }
        },
        {
          "term": {
            "uscan.google.found": true
          }
        },
        {
          "term": {
            "uscan.ebay.found": true
          }
        },
        ... 
      ],
      "minimum_number_should_match": 5
    }
  }
}

暫無
暫無

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

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