Determining which words were matched in a fuzzy search

elasticsearch

Solution

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
            }
        }
    }
}

Problem

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?

Original source