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

Categories

0 votes
752 views
in Technique[技术] by (71.8m points)

elasticsearch - Determining which words were matched in a fuzzy search

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?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...