How to get start offset and end offset of a search string in search result in elasticsearch

Hi team, I have a requirement to find the start and end position of a particular word in a text.

Storing term_vectors and using the Term vectors API might be the best bet?

Thanks for the reply!

Suppose my text is "The patient date of birth is 12/11/2019", and I am searching for "date of birth" in the text. Upon search I need to get the start and end offset of the search string in the search result.

I need a result something like,

"date of birth" : {
    "start_offset" : 12,
    "end_offset" : 25
}

I have explored the term vectors API, but every time when I search, the start offset always starts with 0. In my case my search string offset in whole text is 12.

Thanks

You might find success with Highlighting.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.