search - How to rank elasticsearch query results by number of matches on the should clause? -


i have following query :

{    "query":{       "bool":{          "should":[             {                "match_phrase":{                   "related":"robotic"                }             },             {                "match_phrase":{                   "related":"robotic arm"                }             },             {                "match_phrase":{                   "related":"robot kit"                }             },             {                "match_phrase":{                   "related":"robot technology"                }             },             {                "match_phrase":{                   "related":"build robot"                }             },             {                "match_phrase":{                   "related":"robot kids"                }             }          ],          "minimum_should_match":"1"       }    } } 

i want rank results number of matches. i.e. result matches 6 should clauses should on top while 1 matches 1 should somewhere near bottom.

how do that?

use query time boosting , can alter order few fields based on different value boost in each term clause.

{     "query": {         "bool": {             "should": [{                     "match_phrase": {                         "related": {                             "query": "robotic",                             "boost": 5                         }                     }                 },                 {                     "match_phrase": {                         "related": {                             "query": "robotic arm",                             "boost": 5                         }                     }                 },                 {                     "match_phrase": {                         "related": {                             "query": "robotic kit",                             "boost": 5                         }                     }                 },                 {                     "match_phrase": {                         "related": {                             "query": "robotic technology",                             "boost": 5                         }                     }                 }             ],             "minimum_should_match": "1"         }     } } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -