# Returning the main document and the tag that matched in a sub document

**URL:** <https://discuss.elastic.co/t/returning-the-main-document-and-the-tag-that-matched-in-a-sub-document/20468>\
**Category:** Elasticsearch\
**Created:** [October 28, 2014, 6:51pm UTC](https://discuss.elastic.co/t/returning-the-main-document-and-the-tag-that-matched-in-a-sub-document/20468 "2014-10-28T18:51:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Maddox](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike_maddox/32/12337_2.png) [@Mike\_Maddox](https://discuss.elastic.co/u/Mike_Maddox)\
**Post date:** [October 28, 2014, 6:51pm UTC](https://discuss.elastic.co/t/returning-the-main-document-and-the-tag-that-matched-in-a-sub-document/20468/1 "2014-10-28T18:51:31Z")

</div>

Any help would be appreciated. I have a parent document that has an array  
of sub documents which are tags that are associated with an objectid which  
is used to identify another element. I am able to search on the tags and  
get a response which returns the parent document which is exactly what I  
want. However, since the tags map to an objectid, I'd like to know which  
keywords matched the tag so I can get the objectid. I can compare the tags  
on the client to figure out which matched, however, if using a stemming  
analyzer, this wouldn't work and I'd like to find a better way if possible.  
For example, if I search for "friend and families" I would get a return of  
the document with id 249184, but I want to find out that we matched a tag  
related to objectid='7'. Any suggestions on if I'm going in the right  
direction to get the results I need or would there be another way to  
structure this.

{  
"\_index": "myindex",  
"\_type": "mytype",  
"\_id": "249184",  
"\_version": 1,  
"\_score": 1,  
"\_source": {  
"id": 249184,  
"info":"I love elasticsearch",  
"mytags": [  
{  
"objectid": 7,  
"tags": [  
"friend and families",  
"brother"  
]  
},  
{  
"objectid": 3,  
"tags": [  
"sister"  
]  
}  
]  
}  
}

The index is defined as follows (has been simplified for this example):

{  
"mydata": {  
"properties": {  
"id": {  
"type": "integer",  
"index": "not\_analyzed"  
},  
"info": {  
"type": "string",  
"analyzer": "standard"  
},  
"mytags": {  
"type" : "object",  
"properties": {  
"objectid": { "type": "integer", "index":  
"not\_analyzed" },  
"tags": { "type": "string", "analyzer": "standard"}  
}  
}  
}  
}  
}

Thanks much

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/00fb58c8-dee5-47d5-a463-e754d28d7b33%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/00fb58c8-dee5-47d5-a463-e754d28d7b33%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:53am UTC](https://discuss.elastic.co/t/returning-the-main-document-and-the-tag-that-matched-in-a-sub-document/20468/2 "2017-07-06T00:53:22Z")

</div>

Closed on July 6, 2017, 12:53am UTC


