# Searching for phrase which will return partial text in the field

**URL:** <https://discuss.elastic.co/t/searching-for-phrase-which-will-return-partial-text-in-the-field/87539>\
**Category:** Elasticsearch\
**Created:** [May 30, 2017, 9:36am UTC](https://discuss.elastic.co/t/searching-for-phrase-which-will-return-partial-text-in-the-field/87539 "2017-05-30T09:36:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshraddha](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@jshraddha](https://discuss.elastic.co/u/jshraddha)\
**Post date:** [May 30, 2017, 9:36am UTC](https://discuss.elastic.co/t/searching-for-phrase-which-will-return-partial-text-in-the-field/87539/1 "2017-05-30T09:36:17Z")

</div>

Hi,

I am learning elasticsearch and tried few queries like match, match phrase, search, fuzzy etc.  
Whenever we search for any text ES returns the document containing that text. I am having a different requirement where I want to search for a text or a phrase and the result should be a range of text which means matching phrase along with couple of words before and after the phrase.

Ex.  
Document is having following text  
**A DFA is defined as an abstract mathematical concept, but is often implemented in hardware and software for solving various specific problems. For example, a DFA can model software that decides whether or not online user input such as email addresses are valid**

If I search for a word let say " **software**"

then it should return  
**often implemented in hardware and software for solving various specific problems**

few words before and after the word **software** should be returned.

Is this available in elasticsearch? If yes can someone suggest what should be used for getting such results.

---

<div class="post-metadata">

**Author:** ![Heinmci](https://avatars.discourse-cdn.com/v4/letter/h/6a8cbe/32.png) [@Heinmci](https://discuss.elastic.co/u/Heinmci)\
**Post date:** [May 30, 2017, 10:30am UTC](https://discuss.elastic.co/t/searching-for-phrase-which-will-return-partial-text-in-the-field/87539/2 "2017-05-30T10:30:19Z")

</div>

Hi,  
I think highlighting is what you're looking for :  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html)

---

<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:** [June 27, 2017, 10:30am UTC](https://discuss.elastic.co/t/searching-for-phrase-which-will-return-partial-text-in-the-field/87539/3 "2017-06-27T10:30:36Z")

</div>

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