# Searching inside array of nested object and retrieving value of the matching nested object

**URL:** https://discuss.elastic.co/t/searching-inside-array-of-nested-object-and-retrieving-value-of-the-matching-nested-object/19921
**Category:** Elasticsearch
**Created:** [September 22, 2014, 7:29pm UTC](https://discuss.elastic.co/t/searching-inside-array-of-nested-object-and-retrieving-value-of-the-matching-nested-object/19921 "2014-09-22T19:29:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![nicom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicom/32/488_2.png) [@nicom](https://discuss.elastic.co/u/nicom)
#### Post date: [September 22, 2014, 7:29pm UTC](https://discuss.elastic.co/t/searching-inside-array-of-nested-object-and-retrieving-value-of-the-matching-nested-object/19921/1 "2014-09-22T19:29:55Z")

</div>

I have products with array of stores containing store\_id and the price of  
the product for the store

{  
label: " product 1 "  
stores: [  
{store\_id: 1, price:1.0},  
{store\_id:2, price: 2.0}  
]  
}

{  
label: " product 2 "  
stores: [  
{store\_id: 1,price: 12.0},  
{store\_id: 2, price: 22.0}  
]  
}

I search all the products present in store 2.  
{  
"query": {  
"match": {  
"stores.store\_id": "2"  
}  
}  
}

however I wont know the associated price since all the prices with all the  
associated stores will be returned.

How to retrieve only the price of the store\_id 2 , and not get all the  
prices?

--  
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/fbc69f17-0ef9-4b15-80ed-736754bdefcc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fbc69f17-0ef9-4b15-80ed-736754bdefcc%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 22, 2014, 7:32pm UTC](https://discuss.elastic.co/t/searching-inside-array-of-nested-object-and-retrieving-value-of-the-matching-nested-object/19921/2 "2014-09-22T19:32:39Z")

</div>

If you need to retrieve a price, index a price, not a product.

If you can’t index only a price with all its needed values (I mean values from product), index a product and prices as children.  
See parent/child: [http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/parent-child-mapping.html](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/parent-child-mapping.html)

--  
David Pilato | Technical Advocate | [elasticsearch.com](http://elasticsearch.com)  
[david.pilato@elasticsearch.com](mailto:david.pilato@elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 22 septembre 2014 à 21:29:59, NM ([n.maisonneuve@gmail.com](mailto:n.maisonneuve@gmail.com)) a écrit:

I have products with array of stores containing store\_id and the price of the product for the store

{  
label: " product 1 "  
stores: [  
{store\_id: 1, price:1.0},  
{store\_id:2, price: 2.0}  
]  
}

{  
label: " product 2 "  
stores: [  
{store\_id: 1,price: 12.0},  
{store\_id: 2, price: 22.0}  
]  
}

I search all the products present in store 2.  
{  
"query": {  
"match": {  
"stores.store\_id": "2"  
}  
}  
}

however I wont know the associated price since all the prices with all the associated stores will be returned.

How to retrieve only the price of the store\_id 2 , and not get all the prices?

--  
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/fbc69f17-0ef9-4b15-80ed-736754bdefcc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fbc69f17-0ef9-4b15-80ed-736754bdefcc%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/etPan.54207957.75a2a8d4.825%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.54207957.75a2a8d4.825%40MacBook-Air-de-David.local).  
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, 1:00am UTC](https://discuss.elastic.co/t/searching-inside-array-of-nested-object-and-retrieving-value-of-the-matching-nested-object/19921/3 "2017-07-06T01:00:34Z")

</div>


