how to control score of Elasticsearch Fuzzines

Viewed 23

I have a dataset of company names. each record contains the name of the company, and also some other values that can represent the name. for example: name: sam's club other_names: sam's west

now the problem is that if i will look for a company called "blala west", that doesn't exists in the DB, I will get this record back with a high score. I have to search for the "other_names" field as well, because I do want that "sam's west" will get back.

what is my best option to handle this?

the query we are using:

  "query": {
    "multi_match": {
      "query": "blabla west",
      "fields": [
        "company_name^2",
        "other_names^1"
      ],
      "fuzziness": "auto"
    }
  }
1 Answers

You can use below query which will help you to boost document which are matching with the exact query values. Also, you can set operator value as or for getting result if any one term match.

{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "blabla west",
            "fields": [
              "company_name^2",
              "other_names^1"
            ],
            "operator": "or",
            "fuzziness": "auto"
          }
        }
      ],
      "should": [
        {
          "multi_match": {
            "query": "blabla west",
            "fields": [
              "company_name^2",
              "other_names^1"
            ],
            "operator": "or",
            "fuzziness": 0
          }
        }
      ]
    }
  }
}
Related