# Query match\_phrase in Nested filed

**URL:** <https://discuss.elastic.co/t/query-match-phrase-in-nested-filed/355337>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [March 13, 2024, 6:26pm UTC](https://discuss.elastic.co/t/query-match-phrase-in-nested-filed/355337 "2024-03-13T18:26:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedri6891](https://avatars.discourse-cdn.com/v4/letter/p/fbc32d/32.png) [@pedri6891](https://discuss.elastic.co/u/pedri6891)\
**Post date:** [March 13, 2024, 6:26pm UTC](https://discuss.elastic.co/t/query-match-phrase-in-nested-filed/355337/1 "2024-03-13T18:26:27Z")

</div>

Hello, I have an index with a nested field called lines with values  
[  
{  
"text": "Other congestive heart failure"  
},  
{  
"text": "Staging is recommended"  
},  
],  
I want to make a query by match\_phrase within the lines field where the phrase is "Congestive Heart failure Staging is recommended"

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [March 13, 2024, 6:37pm UTC](https://discuss.elastic.co/t/query-match-phrase-in-nested-filed/355337/2 "2024-03-13T18:37:22Z")

</div>

Hey there, unfortunately [nested](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html) fields actually index the content as separate documents, so you can't perform that type of search out of the box.

You could experiment with a boolean query that searched for each field, but given your question I'm not 100% sure that would meet your needs.

Are you sure you need a nested field for this use case? Or could you index this content in another field for this type of text search?

---

<div class="post-metadata">

**Author:** ![pedri6891](https://avatars.discourse-cdn.com/v4/letter/p/fbc32d/32.png) [@pedri6891](https://discuss.elastic.co/u/pedri6891)\
**Post date:** [March 13, 2024, 6:50pm UTC](https://discuss.elastic.co/t/query-match-phrase-in-nested-filed/355337/3 "2024-03-13T18:50:44Z")

</div>

Yes, I have a content field where I store all the text, but each item in the nested field stores line coordinates, and when I search for the complete phrase I want to highlight the lines where that phrase appears

---

<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:** [April 10, 2024, 6:51pm UTC](https://discuss.elastic.co/t/query-match-phrase-in-nested-filed/355337/4 "2024-04-10T18:51:01Z")

</div>

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