0

I have the 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 a robot"
               }
            },
            {
               "match_phrase":{
                  "related":"robot for kids"
               }
            }
         ],
         "minimum_should_match":"1"
      }
   }
}

I want to rank the results by number of matches. i.e. the result which matches all 6 should clauses should be on top while the one that matches only one should be somewhere near the bottom.

How do I do that?

Community
  • 1
  • 1

1 Answers1

0

use query time boosting and you can also alter the order for few fields based on different value for 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"
        }
    }
}
user3775217
  • 4,675
  • 1
  • 22
  • 33