Elasticsearch用于获取阈值命中的嵌套查询



我有如下嵌套索引结构:

{
   "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,...

每条记录可能有一百个客户,我想查询大于5的find=true(每条记录至少有5个客户find=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
    }
  }
}

最新更新