'Elasticsearch fuzzy matching: How can I get direct hits first?

I'm using Elasticsearch to search names in a database, and I want it to be fuzzy to allow for minor spelling errors. Based on the advice I've found on the matter, I'm using "match" and "fuzziness" instead of "fuzzy", which definitely seems to be more accurate. This is my query:

{ "query": 
    { "match": 
        { "last_name": 
            { "query": "Beach", 
              "type": "phrase",
              "fuzziness": 2
            } 
        }
     }
}

However, even though I have numerous results with last_name "Beach" (I know there's at least 100), I also get results with last_name "Beech" and "Berch" in the first 10 hits returned by my query. Can someone help me figure out how to get the exact matches first?



Solution 1:[1]

I tried to edit "Constantijn" answer above to include sample based on his answer, but still not appearing (pending approval). So, I will just put a sample here instead...

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "last_name": {
              "query": "Beach",
              "fuzziness": 2,
              "boost": 1
            }
          }
        },
        {
          "match": {
            "last_name": {
              "query": "Beach",
              "boost": 10
            }
          }
        }
      ]
    }
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3663854