# Finding which elements of an array are the ones that matched in search results

**URL:** <https://discuss.elastic.co/t/finding-which-elements-of-an-array-are-the-ones-that-matched-in-search-results/8238>\
**Category:** Elasticsearch\
**Created:** [June 27, 2012, 8:27am UTC](https://discuss.elastic.co/t/finding-which-elements-of-an-array-are-the-ones-that-matched-in-search-results/8238 "2012-06-27T08:27:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Russell\_Mull](https://avatars.discourse-cdn.com/v4/letter/r/a9a28c/32.png) [@Russell\_Mull](https://discuss.elastic.co/u/Russell_Mull)\
**Post date:** [June 27, 2012, 8:27am UTC](https://discuss.elastic.co/t/finding-which-elements-of-an-array-are-the-ones-that-matched-in-search-results/8238/1 "2012-06-27T08:27:58Z")

</div>

I have a document which looks something like this:

{  
content: [  
"The first entry is ok",  
"But the second entry is great!"  
]  
}

I can find this document when I search for 'great' under content, but I'd  
like to find out that the second element of 'content' is the one that  
matched. I can do this by hand, but that's clearly less than ideal.

The only way I've found so far is to abuse the highlighter like this:

"highlight" : {  
"pre\_tags" : [""],  
"post\_tags" : [""],  
"fields" : {  
"content" : {}  
}  
}

This causes only the entries that matched to show up in highlight.content  
in the results. But this seems less than ideal. Is there a better way to do  
it?

Thanks,  
Russell

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [June 27, 2012, 8:48am UTC](https://discuss.elastic.co/t/finding-which-elements-of-an-array-are-the-ones-that-matched-in-search-results/8238/2 "2012-06-27T08:48:25Z")

</div>

> I can find this document when I search for 'great' under content, but  
> I'd like to find out that the second element of 'content' is the one  
> that matched. I can do this by hand, but that's clearly less than  
> ideal.
> 
> The only way I've found so far is to abuse the highlighter like this:

> This causes only the entries that matched to show up in  
> highlight.content in the results. But this seems less than ideal. Is  
> there a better way to do it?

Currently there isn't a better way to do this. There are various issues  
open about this and similar features with nested docs. Definitely  
should be on the roadmap

clint

---

<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:** [July 6, 2017, 3:22am UTC](https://discuss.elastic.co/t/finding-which-elements-of-an-array-are-the-ones-that-matched-in-search-results/8238/3 "2017-07-06T03:22:21Z")

</div>


