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

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/fbc69f17-0ef9-4b15-80ed-736754bdefcc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

--
David Pilato | Technical Advocate | elasticsearch.com
david.pilato@elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 22 septembre 2014 à 21:29:59, NM (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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/fbc69f17-0ef9-4b15-80ed-736754bdefcc%40googlegroups.com.
For more options, visit 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.
To view this discussion on the web visit 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.