Using minimum_should_match in filtered elasticSearch query -


i have filtered elasticsearch query works, want use minimum_should_match instruct es return results have @ least 3 should matches. can't seem figure out put minimum_should_match. should put it?

{   "size": 100,   "sort": {     "price_monthly": "asc"   },   "query": {     "filtered": {       "query": {         "match_all": []       },       "filter": {         "bool": {           "must": [],           "should": [             [               {                 "range": {                   "mb.untouched": {                     "gte": "0",                     "lt": "500"                   }                 }               },               {                 "range": {                   "mb.untouched": {                     "gte": "500",                     "lt": "1000"                   }                 }               }             ],             [               {                 "range": {                   "minutes.untouched": {                     "gte": "0",                     "lt": "100"                   }                 }               },               {                 "range": {                   "minutes.untouched": {                     "gte": "200",                     "lt": "300"                   }                 }               }             ],             [               {                 "range": {                   "sms.untouched": {                     "gte": "750",                     "lt": "1000"                   }                 }               }             ]           ],           "must_not": {             "missing": {               "field": "provider.untouched"             }           }         }       },       "strategy": "query_first"     }   },   "aggs": {     "provider.untouched": {       "terms": {         "field": "provider.untouched"       }     },     "prolong.untouched": {       "terms": {         "field": "prolong.untouched"       }     },     "duration.untouched": {       "terms": {         "field": "duration.untouched"       }     },     "mb.untouched": {       "histogram": {         "field": "mb.untouched",         "interval": 500,         "min_doc_count": 1       }     },     "sms.untouched": {       "histogram": {         "field": "sms.untouched",         "interval": 250,         "min_doc_count": 1       }     },     "minutes.untouched": {       "histogram": {         "field": "minutes.untouched",         "interval": 100,         "min_doc_count": 1       }     },     "price_monthly.untouched": {       "histogram": {         "field": "price_monthly.untouched",         "interval": 5,         "min_doc_count": 1       }     }   } } 

in order use minimum_should_match, need rewrite filtered query little bit, i.e. need move should clause query part of filtered query , keep must_not in filter part (because missing filter). can add minimum_should_match: 3 in bool query part shown below:

{   "size": 100,   "sort": {     "price_monthly": "asc"   },   "query": {     "filtered": {       "query": {         "bool": {           "minimum_should_match": 3,           "must": [],           "should": [             [               {                 "range": {                   "mb.untouched": {                     "gte": "0",                     "lt": "500"                   }                 }               },               {                 "range": {                   "mb.untouched": {                     "gte": "500",                     "lt": "1000"                   }                 }               }             ],             [               {                 "range": {                   "minutes.untouched": {                     "gte": "0",                     "lt": "100"                   }                 }               },               {                 "range": {                   "minutes.untouched": {                     "gte": "200",                     "lt": "300"                   }                 }               }             ],             [               {                 "range": {                   "sms.untouched": {                     "gte": "750",                     "lt": "1000"                   }                 }               }             ]           ]         }       },       "filter": {         "bool": {           "must_not": {             "missing": {               "field": "provider.untouched"             }           }         }       },       "strategy": "query_first"     }   },   "aggs": {     "provider.untouched": {       "terms": {         "field": "provider.untouched"       }     },     "prolong.untouched": {       "terms": {         "field": "prolong.untouched"       }     },     "duration.untouched": {       "terms": {         "field": "duration.untouched"       }     },     "mb.untouched": {       "histogram": {         "field": "mb.untouched",         "interval": 500,         "min_doc_count": 1       }     },     "sms.untouched": {       "histogram": {         "field": "sms.untouched",         "interval": 250,         "min_doc_count": 1       }     },     "minutes.untouched": {       "histogram": {         "field": "minutes.untouched",         "interval": 100,         "min_doc_count": 1       }     },     "price_monthly.untouched": {       "histogram": {         "field": "price_monthly.untouched",         "interval": 5,         "min_doc_count": 1       }     }   } } 

Comments