# How to get positions of the matched string?

**URL:** https://discuss.elastic.co/t/how-to-get-positions-of-the-matched-string/291199
**Category:** Elasticsearch
**Created:** [December 8, 2021, 9:34am UTC](https://discuss.elastic.co/t/how-to-get-positions-of-the-matched-string/291199 "2021-12-08T09:34:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![wildansupernova](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wildansupernova/32/97688_2.png) [@wildansupernova](https://discuss.elastic.co/u/wildansupernova)
#### Post date: [December 8, 2021, 9:34am UTC](https://discuss.elastic.co/t/how-to-get-positions-of-the-matched-string/291199/1 "2021-12-08T09:34:20Z")

</div>

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.

Example

- 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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [January 5, 2022, 9:35am UTC](https://discuss.elastic.co/t/how-to-get-positions-of-the-matched-string/291199/2 "2022-01-05T09:35:00Z")

</div>

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