Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I struggle to perform a fuzzy search with Elasticsearch 7.10.

My request is the following:

{
  "size": 5,
  "from": 0,
  "query": {
    "fuzzy": {
      "name": {
        "value": "P2",
        "fuzziness": "AUTO",
        "prefix_length": 0,
        "max_expansions": 50
      }
    }
  },
  "track_scores": false
}

While I have a record looking like:

{
  "bookId": "book-2",
  "name": "Programming #2",
  "entries": 36
}

The name is declared as {type: "text", fielddata: true}, and, despite that, I have no result. Can you give me a hint regarding my mistake?

question from:https://stackoverflow.com/questions/65940815/elasticsearch-does-not-fuzzy

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
236 views
Welcome To Ask or Share your Answers For Others

1 Answer

From docs:

Returns documents that contain terms similar to the search term, as measured by a Levenshtein edit distance.

An edit distance is the number of one-character changes needed to turn one term into another. These changes can include:

  • Changing a character (box → fox)
  • Removing a character (black → lack)
  • Inserting a character (sic → sick)
  • Transposing two adjacent characters (act → cat)

Your query "P2" doesn't match any of these cases. You might achieve this kind of behavior by changing source data or implementing analyzers that handle these kinds of use cases.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...