# Nested Documents - Search for nested elements

**URL:** <https://discuss.elastic.co/t/nested-documents-search-for-nested-elements/60002>\
**Category:** Elasticsearch\
**Created:** [September 7, 2016, 3:19pm UTC](https://discuss.elastic.co/t/nested-documents-search-for-nested-elements/60002 "2016-09-07T15:19:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chakkasm](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@chakkasm](https://discuss.elastic.co/u/chakkasm)\
**Post date:** [September 7, 2016, 3:19pm UTC](https://discuss.elastic.co/t/nested-documents-search-for-nested-elements/60002/1 "2016-09-07T15:19:51Z")

</div>

I have Order details and Order Items as nested documents. This means one order will have multiple order item details.

Let's say the item details has item name and when user searches for a particular item, I need to display order number, order amount, item name (only matching - not all).

How do I achieve this. When I do a nested query, the whole document along with other items details is fetched, but I cannot display other items which were not searched..

I am currently using Elasticsearch 2.3.4 version.

## Sample data

{  
"Order Id" : 123456,  
"Order Amount" : 20000,  
"Item Details" : [  
{ "Item Name" : "Pencil", "Quantity" : 100 },  
{ "Item Name" : "Pen", "Quantity" : 150 },  
{ "Item Name" : "Books", "Quantity" : 300 }  
]  
}

## Output : When searched for Books

{  
"Order Id" : 123456,  
"Order Amount" : 20000,  
"Item Details" : [  
{ "Item Name" : "Books", "Quantity" : 300 }  
]  
}

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [September 7, 2016, 5:30pm UTC](https://discuss.elastic.co/t/nested-documents-search-for-nested-elements/60002/2 "2016-09-07T17:30:39Z")

</div>

You can get the order id and amount by specifying these fields in the `_source` parameter of your query and you can get back the matching nested object using [`inner_hits`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html) feature of the nested query.

---

<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 5, 2017, 10:22pm UTC](https://discuss.elastic.co/t/nested-documents-search-for-nested-elements/60002/3 "2017-07-05T22:22:01Z")

</div>

Closed on July 5, 2017, 10:22pm UTC


