Ramesh
Ramesh

Reputation: 1942

Elasticsearch : Improving multi_match results

Hi I am trying to search a value in a different fields. I am using multi_match with cross_fields type. Here is the query

"query": {
    "filtered": {
      "query": {
        "bool": {
          "must": [
            {
              "multi_match": {
                "query": "red cross",
                "type": "cross_fields",
                "fields": [
                  "name^20",
                  "keywords^12",
                  "description^1"
                ]
              }
            }
          ]
        }
      }
    }   }

Results I am getting for the above query

 "results": [
        {
            "name": "CrossPurpose",
            .....
        } ,
        {
            "name": "Community Center",
            "keywords": "American Red Cross,Red Cross,Center,Blood",
            . . .
          },
          {
             "name": "Some Group",
             "description":".... red cross ..."
          },
          .......
          ....
          ..
          {
             "name" : "Red cross" ,
              .....
          }
          ]

I want to improve the search results.

I want to see the record with name "Red cross" in the first position. First it should match as whole word "red cross" then only it should match "red" , "cross".

I want preference to be given more for name field than keywords and description.

Please help me to improve the query . Thanks in advance.

Upvotes: 0

Views: 110

Answers (1)

chetan varma
chetan varma

Reputation: 524

You need to use type = best_fields

so your query will be

{
  "query": {
    "multi_match" : {
      "query":      "red cross",
      "type":       "best_fields",
      "fields":     [ "name", "keywords", "description" ],
      "tie_breaker": 0.3
    }
  }
}

Upvotes: 1

Related Questions