# Can Elasticsearch return position of the text within document

**URL:** <https://discuss.elastic.co/t/can-elasticsearch-return-position-of-the-text-within-document/312901>\
**Category:** Elasticsearch\
**Created:** [August 25, 2022, 10:15am UTC](https://discuss.elastic.co/t/can-elasticsearch-return-position-of-the-text-within-document/312901 "2022-08-25T10:15:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dinesh\_Zende](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_zende/32/110098_2.png) [@Dinesh\_Zende](https://discuss.elastic.co/u/Dinesh_Zende)\
**Post date:** [August 25, 2022, 10:15am UTC](https://discuss.elastic.co/t/can-elasticsearch-return-position-of-the-text-within-document/312901/1 "2022-08-25T10:15:58Z")

</div>

I have created index with the attributes \<Filename,pageno, content\>, where the contents are the page content of the document.  
When I search for the particular query, it returns the appropriate Filename, Pageno. But to be more precise, I want the position of the search result within the document.  
Is there any method for getting the same.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [August 25, 2022, 10:55am UTC](https://discuss.elastic.co/t/can-elasticsearch-return-position-of-the-text-within-document/312901/2 "2022-08-25T10:55:57Z")

</div>

Hi @Dinesh_Zende .

I understand that if you search for "mathematics" and the answer is the document "mathematics class" you want a field with the value 0 due to the position of the term "mathematics" in the text "mathematics class".  
Is there any impediment to carrying out this logic in your application?

---

<div class="post-metadata">

**Author:** ![Dinesh\_Zende](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_zende/32/110098_2.png) [@Dinesh\_Zende](https://discuss.elastic.co/u/Dinesh_Zende)\
**Post date:** [August 25, 2022, 11:07am UTC](https://discuss.elastic.co/t/can-elasticsearch-return-position-of-the-text-within-document/312901/3 "2022-08-25T11:07:08Z")

</div>

Thanks @RabBit_BR for your quick reply.  
Actually I want to highlight that part of the text in PDF file, returned by the search results. (if possible the whole related paragraph)

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [August 25, 2022, 11:28am UTC](https://discuss.elastic.co/t/can-elasticsearch-return-position-of-the-text-within-document/312901/4 "2022-08-25T11:28:00Z")

</div>

Maybe if you give more details of your data, some example for a simulation.

I believe you need the [highlighting](https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html).

---

<div class="post-metadata">

**Author:** ![Dinesh\_Zende](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_zende/32/110098_2.png) [@Dinesh\_Zende](https://discuss.elastic.co/u/Dinesh_Zende)\
**Post date:** [August 25, 2022, 11:45am UTC](https://discuss.elastic.co/t/can-elasticsearch-return-position-of-the-text-within-document/312901/5 "2022-08-25T11:45:59Z")

</div>

Appreciate it @RabBit_BR  
I will try to implement it.  
Actually, I have PDF Repositories and then I have spllited it in pages and added as a document in the index.  
So will this help to highight the PDF (though I have not read it properly)

---

<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:** [September 22, 2022, 11:46am UTC](https://discuss.elastic.co/t/can-elasticsearch-return-position-of-the-text-within-document/312901/6 "2022-09-22T11:46:39Z")

</div>

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