Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to boost exact match over multi match in elastic search

I am running a following query to boost exact match over multi_match in elastic search. But, not getting the expected results.

My goal is to boost in following order: "java developer" > java AND developer > java OR developer

Can someone help in troubleshooting this? Need to know how do I give boost to match_phrase here and how to add remaining fields in match_phrase

"query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "java developer",
            "fields": [
              "title",
              "content",
              "tags",
              "summary"
            ]
          }
        }
      ],
      "should": [
        {
          "match_phrase": {
            "title": "java developer"
          }
        },
        {
          "multi_match": {
            "query": "java developer",
            "fields": [
              "title",
              "content",
              "tags",
              "summary"
            ],
            "operator": "and",
            "boost": 4
          }
        }
      ]
    }
  }

Thanks so much for your help.

like image 660
Vishal Sharma Avatar asked Aug 05 '15 07:08

Vishal Sharma


People also ask

What is boost in elastic search?

Returns documents matching a positive query while reducing the relevance score of documents that also match a negative query. You can use the boosting query to demote certain documents without excluding them from the search results.

What is minimum should match Elasticsearch?

Minimum Should Match is another search technique that allows you to conduct a more controlled search on related or co-occurring topics by specifying the number of search terms or phrases in the query that should occur within the records returned.

What is Elasticsearch Match_phrase?

Match phrase queryeditA phrase query matches terms up to a configurable slop (which defaults to 0) in any order. Transposed terms have a slop of 2.

What is the difference between match and term query in Elasticsearch?

To better search text fields, the match query also analyzes your provided search term before performing a search. This means the match query can search text fields for analyzed tokens rather than an exact term. The term query does not analyze the search term. The term query only searches for the exact term you provide.


1 Answers

Here is what worked for me:

  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "java developer",
            "fields": [
              "title",
              "content",
              "tags",
              "summary"
            ]
          }
        }
      ],
      "should": [
        {
          "multi_match": {
            "query": "java developer",
            "fields": [
              "title",
              "content",
              "tags",
              "summary"
            ],
            "type": "phrase",
            "boost": 10
          }
        },
        {
          "multi_match": {
            "query": "java developer",
            "fields": [
              "title",
              "content",
              "tags",
              "summary"
            ],
            "operator": "and",
            "boost": 4
          }
        }
      ]
    }
  }
like image 122
Vishal Sharma Avatar answered Sep 21 '22 18:09

Vishal Sharma