I'm running a fuzzy search, and need to see which words were matched. For example, if I am searching for the query testing
, and it matches a field with the sentence The boy was resting
, I need to be able to know that the match was due to the word resting
.
I tried setting the parameter explain = true
, but it doesn't seem to contain the information I need. Any thoughts?
For the fuzzy matching method, various fuzzy matching algorithms can be used. Each matching algorithm is scored based on how closely it matches the two fields. For example, if you select exact matching and the two fields match, the match score is 100. If the two fields don't match, the score is 0.
What is fuzzy name matching? Fuzzy matching assigns a probability to a match between 0.0 and 1.0 based on linguistic and statistical methods instead of just choosing either 1 (true) or 0 (false). As a result, names Robert and Bob can be a match with high probability even though they're not identical.
Fuzzy Matching (also called Approximate String Matching) is a technique that helps identify two elements of text, strings, or entries that are approximately similar but are not exactly the same. For example, let's take the case of hotels listing in New York as shown by Expedia and Priceline in the graphic below.
Alright, this is what I was looking for:
After a bit of research, I found the Highlighting feature of elasticsearch.
By default it returns a snippet of context surrounding the match, but you can set the fragment size to the query length to return only the exact match. For example:
{
query : query,
highlight : {
"fields" : {
'text' : {
"fragment_size" : query.length
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With