0

I have an elastic query that contains a multi-match query in it..

 "multi_match" => [
        "query" => "Will Smith"
        "type" => "best_fields"
        "fields" => [
          "title^10",
          "description^7",
          "keywords",
          "name"
        ]
        "operator" => "and"
      ]

I want to Add two function-score query for multi-match query... and give a higher weigh to multi-match query with phrase type.. and a less weigh to multi-match query that has best_fields type...

I mean the documents that has the keyword exactly like what I searched must have higher _score

I wrote the query and function_score in a bool and must query... but the result did not changed..

does anyone any idea how to manage my query to get better results?

thanks.

maral
  • 97
  • 2
  • 11

1 Answers1

4

I can show you how I've done something similar. Take a look at below query:

{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "SEARCH TERM HERE",
            "fields": [
              "title^70",
              "description^30",
              "content^20"
            ],
            "type": "phrase",
            "boost": 100
          }
        },
        {
          "multi_match": {
            "query": "SEARCH TERM HERE",
            "fields": [
              "title^30",
              "description^25",
              "content^10"
            ],
            "type": "most_fields",
            "minimum_should_match": "100%",
            "boost": 50
          }
        },
        {
          "multi_match": {
            "query": "SEARCH TERM HERE",
            "fields": [
              "title^25",
              "description^15",
              "content^10"
            ],
            "type": "most_fields",
            "minimum_should_match": "50%",
            "boost": 25
          }
        },
        ...
      ]
    }
  }
}

First multi_match is matching documents only when full search phrase is found and boost entire result with 100.

Second part searches for 100% words from search term. So the order of words does not matter but all of them must appear in searched document. Boost = 50.

Third part searches for 50% match. Means not all words have to be in document to return it in results. Boost = 25.

The ... part means that I have something more for rest of the results. But it is not needed in each case.

The boost values are selected by myself in many tries and could not be good for every single case. You have to remember that behind of relevancy there is a quite complex algorithm. For more info take a look into:

Piotr Pradzynski
  • 4,190
  • 5
  • 23
  • 43