# Getting matched subdocument in nested type

**URL:** <https://discuss.elastic.co/t/getting-matched-subdocument-in-nested-type/12050>\
**Category:** Elasticsearch\
**Created:** [May 21, 2013, 9:07am UTC](https://discuss.elastic.co/t/getting-matched-subdocument-in-nested-type/12050 "2013-05-21T09:07:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chetana](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@Chetana](https://discuss.elastic.co/u/Chetana)\
**Post date:** [May 21, 2013, 9:07am UTC](https://discuss.elastic.co/t/getting-matched-subdocument-in-nested-type/12050/1 "2013-05-21T09:07:30Z")

</div>

I index varing multi level nested objects. When the search results are  
returned is there any way returning just the matched subdocument using  
script or filter mechanism

My mapping looks like

{"nested\_mapping":{  
"properties":{  
"desp":{"type":"string"},  
"id":{"type":"string",  
"store":"yes"},"name":{"type":"string","store":"yes"},"  
subprocess":{"type":"nested","include\_in\_root":true,  
"properties":{"id":{"type":"string"},  
"name":{"type":"string"}  
}}}

Indexed documents are :

1. {"id":"level2","desp":"simple desc","subprocess":{"name":"L3"}}

2. 

{"id":"level0","name":"L0","subprocess":{"id":"level1","name":"L1","subprocess":{"id":"level2","name":"L2","subprocess":{"id":"level3","name":"L3","desp":"Level  
3 process"}}}}

I am getting both records (entire json source) for the search query "Q3".  
What mechanism I should use if I just need to get sub documents (just  
the matched nested part in the multi-level nesting) i.e.  
subprocess":{"name":"L3"} and  
subprocess:{"id":"level3","name":"L3","desp":"Level 3 process"}

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 22, 2013, 5:01am UTC](https://discuss.elastic.co/t/getting-matched-subdocument-in-nested-type/12050/2 "2013-05-22T05:01:56Z")

</div>

Returning only the matched nested documents is not yet supported by  
Elasticsearch: [Return matching nested inner objects per hit · Issue #3022 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3022)

You would need to resolve this issue on the client side for now.

--  
Ivan

On Tue, May 21, 2013 at 2:07 AM, Chetana [ambha.career@gmail.com](mailto:ambha.career@gmail.com) wrote:

> I index varing multi level nested objects. When the search results are  
> returned is there any way returning just the matched subdocument using  
> script or filter mechanism
> 
> My mapping looks like
> 
> {"nested\_mapping":{  
> "properties":{  
> "desp":{"type":"string"},  
> "id":{"type":"string",  
> "store":"yes"},"name":{"type":"string","store":"yes"},"  
> subprocess":{"type":"nested","include\_in\_root":true,  
> "properties":{"id":{"type":"string"},  
> "name":{"type":"string"}  
> }}}
> 
> Indexed documents are :
> 
> 1. {"id":"level2","desp":"simple desc","subprocess":{"name":"L3"}}
> 
> 2. 
> 
> {"id":"level0","name":"L0","subprocess":{"id":"level1","name":"L1","subprocess":{"id":"level2","name":"L2","subprocess":{"id":"level3","name":"L3","desp":"Level  
> 3 process"}}}}
> 
> I am getting both records (entire json source) for the search query "Q3".  
> What mechanism I should use if I just need to get sub documents (just  
> the matched nested part in the multi-level nesting) i.e.  
> subprocess":{"name":"L3"} and  
> subprocess:{"id":"level3","name":"L3","desp":"Level 3 process"}
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:35am UTC](https://discuss.elastic.co/t/getting-matched-subdocument-in-nested-type/12050/3 "2017-07-06T02:35:27Z")

</div>


