简体   繁体   中英

Elasticsearch nested query for getting threshold hit

I have the nested index structure as following:

{
   "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"}
            }
        }
     }
   }
}

The example data such as: uscan.ebay.found:true,uscan.ibm.found:true,uscan.google.found:false,...

Each record may have one hundred customers, I wanna query the found=true greater than 5 (each record at least have 5 customers found=true). Any ideas please, thanks!

You can use minimum_should_match for this to specify the minimum number of conditions in a should clause that should match. Use the query below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM