How to get positions of the matched string?

Sorry I am new to Elasticsearch

I have already searched through internet, some technique I found useful is around highlighting.

But I want to ask is there any way to fulfill this scenario other than using highlighting.


  • fieldTextToSearch: "I want to eat"

I will try to match "ant to".

My current solution is just use highlighting and I will traverse the highlighted result for searching the positions. but it seems weird.

What do I want is like below

My ideal search result would be (tokenized space positions)

  • startToken=1
  • startChar=1
  • endToken=2
  • endChar=1

If it seems not possible, can it give me the result at least like this? (full text positions )

  • startChar = 3
  • endChar = 8

can you give me some best practices for this scenario? Thanks a lot

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