ren1199
ren1199

Reputation: 93

Search returning different value in fuzzy Query- Elasticsearch

I have an Elasticsearch fuzzy query as below:

GET /resume/candidate/_search
{
    "query": {
       "fuzzy" : {  "name" : {
                    "value": "Tam",
                    "fuzziness" :     2,
                    "max_expansions": 50 }
    }
}
}

I have the names Tom, Roy, Maxwell in my Index. The name Tom is matched as per the request, but the name Roy also gets returned. How is this happening? The full names are:

Roy M Lovejoy III

Tom Atwell

Also, if i set the fuzziness to 1, I am not getting any result. Shouldn't Tom be matched as only 1 character is different?

Mapping:

{
  "resume": {
    "aliases": {},
    "mappings": {
      "candidate": {
        "properties": {
          "name": {
            "type": "text"
          }
    }
}
}
}

I also have an analyzer, but it is not used in the name field

Analyzer:

"analysis": {
          "analyzer": {
            "case_insensitive": {
              "filter": [
                "lowercase"
              ],
              "tokenizer": "keyword"
            }
          }
        }

Upvotes: 0

Views: 213

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

"Tam" is not a fuzzy match with "roy", it is a match with the middle initial "m", which has an edit distance of 2.

The reason you are not getting a result on "tom" with an edit distance of 1, is because, while your indexed names are being analyzed, and thus lowercased, your query is not. You could lowercase your query, or you could use a fuzzy match query, which would be analyzed:

"query": {
  "match": {
    "name": {
      "query":     "Tam",
      "fuzziness": "AUTO"
    }
  }
}

Upvotes: 3

Related Questions