18

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.

j0k
  • 22,600
  • 28
  • 79
  • 90
Vishal Sharma
  • 591
  • 1
  • 6
  • 15
  • Possible duplicate of [elasticsearch boost importance of exact phrase match](https://stackoverflow.com/questions/18481600/elasticsearch-boost-importance-of-exact-phrase-match) – Jonatan Sep 18 '17 at 15:09

2 Answers2

21

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
          }
        }
      ]
    }
  }
j0k
  • 22,600
  • 28
  • 79
  • 90
Vishal Sharma
  • 591
  • 1
  • 6
  • 15
0

Set your multi match query's type to most_fields:

"query": {
  {
    "multi_match" : {
      "query":      "java developer",
      "type":       "best_fields",
      "fields":     ["title", "content", "tags", "summary" ]
    }
  }
}
Erdal G.
  • 2,694
  • 2
  • 27
  • 37
  • I think you misunderstood the question. most_fields wouldn't help because the requirement is to boost on matching multiple terms of the query not multiple fields of the document(s). – John Askew Sep 17 '19 at 19:38