You might want to do the innermost aggregation using the _uid field instead
of the _id field since the latter is not indexed by default. The next
version of Elasticsearch will feature a new aggregation called top_hits (
https://github.com/elasticsearch/elasticsearch/pull/6124) that will allow
to get the top hits per bucket. I think this is what you are looking for?


On Fri, May 23, 2014 at 3:26 PM, <[email protected]> wrote:

> Hello David,
>
> The query you gave me is correct, I don't have the parsing error anymore.
>
> Unfortunately, it does not give the result I expected.
> What I'm trying to get is a minimum price for each of the products, which
> is an aggregation for each of the products retrieved from the query.
>
> Do you have any advice on how to achieve this ?
>
> Thank you
>
> Le vendredi 23 mai 2014 14:52:23 UTC+2, David Pilato a écrit :
>>
>> I think your syntax is incorrect here. It should be something like:
>>
>>
>> GET /products/_search
>> {
>>   "query": {
>>     "match_all": {}
>>   },
>>   "aggs": {
>>     "offers": {
>>       "nested": {
>>         "path": "offers"
>>       },
>>       "aggs": {
>>         "min_price": {
>>           "min": {
>>             "field": "offers.price"
>>           }
>>         },
>>         "offers_to_product": {
>>             "reverse_nested": {
>>               "path": "offers"
>>             },
>>             "aggs": {
>>               "productId_per_offer": {
>>                 "terms": {
>>                   "field": "id"
>>                 }
>>               }
>>             }
>>           }
>>       }
>>     }
>>   }
>> }
>>
>> Not tested though.
>>
>> Note that offers_to_product is an aggs at the same level as min_price.
>>
>> --
>> *David Pilato* | *Technical Advocate* | *Elasticsearch.com*
>> @dadoonet <https://twitter.com/dadoonet> | 
>> @elasticsearchfr<https://twitter.com/elasticsearchfr>
>>
>>
>> Le 23 mai 2014 à 14:35:19, [email protected] ([email protected]) a écrit:
>>
>> Hello,
>> I'm trying to use the new feature described here:
>>  http://www.elasticsearch.org/guide/en/elasticsearch/
>> reference/current/search-aggregations-bucket-reverse-
>> nested-aggregation.html#search-aggregations-bucket-
>> reverse-nested-aggregation
>>
>> I have a structure similar to the one described in the nested aggregation
>> example : http://www.elasticsearch.org/guide/en/elasticsearch/
>> reference/current/search-aggregations-bucket-nested-aggregation.html
>> For one product I have several resellers so I want to know the minimum
>> price for each product.
>>
>> I tried this search, similar to the documentation example:
>>  GET /products/_search
>> {
>>   "query": {
>>     "match_all": {}
>>   },
>>   "aggs": {
>>     "offers": {
>>       "nested": {
>>         "path": "offers"
>>       },
>>       "aggs": {
>>         "min_price": {
>>           "min": {
>>             "field": "offers.price"
>>           }
>>         },
>>         "aggs": {
>>           "offers_to_product": {
>>             "reverse_nested": {
>>               "path": "offers"
>>             },
>>             "aggs": {
>>               "productId_per_offer": {
>>                 "terms": {
>>                   "field": "id"
>>                 }
>>               }
>>             }
>>           }
>>         }
>>       }
>>     }
>>   }
>> }
>>
>> I have a parsing error:
>>  Caused by: org.elasticsearch.search.SearchParseException:
>> [products][4]: query[ConstantScore(*:*)],from[-1],size[-1]: Parse
>> Failure [Could not find aggregator type [offers_to_product] in [aggs]]
>>         at org.elasticsearch.search.aggregations.AggregatorParsers.
>> parseAggregators(AggregatorParsers.java:128)
>>         at org.elasticsearch.search.aggregations.AggregatorParsers.
>> parseAggregators(AggregatorParsers.java:120)
>>         at org.elasticsearch.search.aggregations.AggregatorParsers.
>> parseAggregators(AggregatorParsers.java:77)
>>         at org.elasticsearch.search.aggregations.
>> AggregationParseElement.parse(AggregationParseElement.java:60)
>>
>> What is wrong with my request?
>>
>> Thank you,
>> Stephan
>>  --
>> 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 [email protected].
>>
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%
>> 40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/e24a0b30-dfea-4a2d-8591-4102fbafcc15%40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/e24a0b30-dfea-4a2d-8591-4102fbafcc15%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Adrien Grand

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4q5PJ328EvK5XbKK21n8JmwNi7o6aHCP%2BrPbZdenAcdw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to