# Reverse nested aggregation parsing error

**URL:** https://discuss.elastic.co/t/reverse-nested-aggregation-parsing-error/17692
**Category:** Elasticsearch
**Created:** [May 23, 2014, 12:35pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-parsing-error/17692 "2014-05-23T12:35:14Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![slagraulet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/slagraulet/32/1481_2.png) [@slagraulet](https://discuss.elastic.co/u/slagraulet)
#### Post date: [May 23, 2014, 12:35pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-parsing-error/17692/1 "2014-05-23T12:35:14Z")

</div>

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](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](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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
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).  
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: [May 23, 2014, 12:52pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-parsing-error/17692/2 "2014-05-23T12:52:06Z")

</div>

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](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 23 mai 2014 à 14:35:19, slagraulet@ippon.fr (slagraulet@ippon.fr) 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](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](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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
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).  
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.537f4476.71f32454.99d%40air-de-david](https://groups.google.com/d/msgid/elasticsearch/etPan.537f4476.71f32454.99d%40air-de-david).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![slagraulet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/slagraulet/32/1481_2.png) [@slagraulet](https://discuss.elastic.co/u/slagraulet)
#### Post date: [May 23, 2014, 1:26pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-parsing-error/17692/3 "2014-05-23T13:26:22Z")

</div>

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](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 23 mai 2014 à 14:35:19, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) \<javascript:\> (  
> [slagr...@ippon.fr](mailto:slagr...@ippon.fr) \<javascript:\>) a écrit:
> 
> Hello,  
> I'm trying to use the new feature described here:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](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 :  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> 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)[https://groups.google.com/d/msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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/e24a0b30-dfea-4a2d-8591-4102fbafcc15%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e24a0b30-dfea-4a2d-8591-4102fbafcc15%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [May 23, 2014, 1:49pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-parsing-error/17692/4 "2014-05-23T13:49:45Z")

</div>

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 (  
[Add top\_hits aggregation by martijnvg · Pull Request #6124 · elastic/elasticsearch · GitHub](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, [slagraulet@ippon.fr](mailto:slagraulet@ippon.fr) 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](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > 
> > Le 23 mai 2014 à 14:35:19, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) ([slagr...@ippon.fr](mailto:slagr...@ippon.fr)) a écrit:
> > 
> > Hello,  
> > I'm trying to use the new feature described here:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](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 : [Elasticsearch Platform — Find real-time answers at scale | Elastic](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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > 
> > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%  
> > [40googlegroups.com](http://40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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/e24a0b30-dfea-4a2d-8591-4102fbafcc15%40googlegroups.com](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](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](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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4q5PJ328EvK5XbKK21n8JmwNi7o6aHCP%2BrPbZdenAcdw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4q5PJ328EvK5XbKK21n8JmwNi7o6aHCP%2BrPbZdenAcdw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![slagraulet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/slagraulet/32/1481_2.png) [@slagraulet](https://discuss.elastic.co/u/slagraulet)
#### Post date: [May 23, 2014, 4:05pm UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-parsing-error/17692/5 "2014-05-23T16:05:18Z")

</div>

Thank you  
I see this pull request is now merged on the 1.3 branch so I will try this  
feature to see if it fits our needs.

Le vendredi 23 mai 2014 15:49:51 UTC+2, Adrien Grand a écrit :

> 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 ([Add top\_hits aggregation by martijnvg · Pull Request #6124 · elastic/elasticsearch · GitHub](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, \<[slagr...@ippon.fr](mailto:slagr...@ippon.fr) \<javascript:\>\> 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](http://Elasticsearch.com)_  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > 
> > > Le 23 mai 2014 à 14:35:19, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) ([slagr...@ippon.fr](mailto:slagr...@ippon.fr)) a  
> > > écrit:
> > > 
> > > Hello,  
> > > I'm trying to use the new feature described here:  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](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/](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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > 
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%  
> > > [40googlegroups.com](http://40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > 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)[https://groups.google.com/d/msgid/elasticsearch/e24a0b30-dfea-4a2d-8591-4102fbafcc15%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8644886c-3f48-4ae1-8c08-b4e78feeebc2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8644886c-3f48-4ae1-8c08-b4e78feeebc2%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![slagraulet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/slagraulet/32/1481_2.png) [@slagraulet](https://discuss.elastic.co/u/slagraulet)
#### Post date: [May 27, 2014, 9:35am UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-parsing-error/17692/6 "2014-05-27T09:35:53Z")

</div>

Hello,  
I tried the new top\_hots aggregation and made it work on denormalized data.

However, when I tries to add a filter I ran into the following exception:

[2014-05-27 11:32:12,869][DEBUG][action.search.type] [Cap 'N Hawk]  
failed to reduce search  
org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
execute phase [fetch], [reduce]  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.finishHim(TransportSearchQueryThenFetchAction.java:141)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction$1.onResult(TransportSearchQueryThenFetchAction.java:113)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction$1.onResult(TransportSearchQueryThenFetchAction.java:107)  
at  
org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:526)  
at  
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
at java.lang.Thread.run(Thread.java:745)  
Caused by: java.lang.NullPointerException  
at  
org.apache.lucene.search.TopDocs$ScoreMergeSortQueue.(TopDocs.java:89)  
at org.apache.lucene.search.TopDocs.merge(TopDocs.java:219)  
at org.apache.lucene.search.TopDocs.merge(TopDocs.java:209)  
at  
org.elasticsearch.search.aggregations.bucket.tophits.InternalTopHits.reduce(InternalTopHits.java:107)  
at  
org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:146)  
at  
org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregation.reduce(InternalSingleBucketAggregation.java:82)  
at  
org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:146)  
at  
org.elasticsearch.search.aggregations.bucket.terms.InternalTerms$Bucket.reduce(InternalTerms.java:77)  
at  
org.elasticsearch.search.aggregations.bucket.terms.InternalTerms.reduce(InternalTerms.java:157)  
at  
org.elasticsearch.search.aggregations.bucket.terms.InternalTerms.reduce(InternalTerms.java:37)  
at  
org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:146)  
at  
org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:386)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.innerFinishHim(TransportSearchQueryThenFetchAction.java:152)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.finishHim(TransportSearchQueryThenFetchAction.java:139)  
... 6 more

Here are the gists used to create the data:

- mapping : [Denormalized mapping · GitHub](https://gist.github.com/stephlag/f9402c699374438c3ede)
- data: [Denormalized Input · GitHub](https://gist.github.com/stephlag/ecb5b2dc384a3f07602d)
- queries: [top hits aggregation on denormalized data · GitHub](https://gist.github.com/stephlag/7ad8edf1ab6b757be3b3)

Le vendredi 23 mai 2014 18:05:18 UTC+2, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) a écrit :

> Thank you  
> I see this pull request is now merged on the 1.3 branch so I will try this  
> feature to see if it fits our needs.
> 
> Le vendredi 23 mai 2014 15:49:51 UTC+2, Adrien Grand a écrit :
> 
> > 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 ([Add top\_hits aggregation by martijnvg · Pull Request #6124 · elastic/elasticsearch · GitHub](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, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) 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](http://Elasticsearch.com)_  
> > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > > 
> > > > Le 23 mai 2014 à 14:35:19, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) ([slagr...@ippon.fr](mailto:slagr...@ippon.fr)) a  
> > > > écrit:
> > > > 
> > > > Hello,  
> > > > I'm trying to use the new feature described here:  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](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/](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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > 
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%  
> > > > [40googlegroups.com](http://40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > 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)[https://groups.google.com/d/msgid/elasticsearch/e24a0b30-dfea-4a2d-8591-4102fbafcc15%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)
#### Post date: [May 30, 2014, 7:45am UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-parsing-error/17692/7 "2014-05-30T07:45:15Z")

</div>

This is indeed a bug, thanks for sharing it! This should be easy to fix.

On 27 May 2014 11:35, [slagraulet@ippon.fr](mailto:slagraulet@ippon.fr) wrote:

> Hello,  
> I tried the new top\_hots aggregation and made it work on denormalized data.
> 
> However, when I tries to add a filter I ran into the following exception:
> 
> [2014-05-27 11:32:12,869][DEBUG][action.search.type] [Cap 'N Hawk]  
> failed to reduce search  
> org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
> execute phase [fetch], [reduce]  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.finishHim(TransportSearchQueryThenFetchAction.java:141)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction$1.onResult(TransportSearchQueryThenFetchAction.java:113)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction$1.onResult(TransportSearchQueryThenFetchAction.java:107)  
> at  
> org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:526)  
> at  
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
> at java.lang.Thread.run(Thread.java:745)  
> Caused by: java.lang.NullPointerException  
> at  
> org.apache.lucene.search.TopDocs$ScoreMergeSortQueue.(TopDocs.java:89)  
> at org.apache.lucene.search.TopDocs.merge(TopDocs.java:219)  
> at org.apache.lucene.search.TopDocs.merge(TopDocs.java:209)  
> at  
> org.elasticsearch.search.aggregations.bucket.tophits.InternalTopHits.reduce(InternalTopHits.java:107)  
> at  
> org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:146)  
> at  
> org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregation.reduce(InternalSingleBucketAggregation.java:82)  
> at  
> org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:146)  
> at  
> org.elasticsearch.search.aggregations.bucket.terms.InternalTerms$Bucket.reduce(InternalTerms.java:77)  
> at  
> org.elasticsearch.search.aggregations.bucket.terms.InternalTerms.reduce(InternalTerms.java:157)  
> at  
> org.elasticsearch.search.aggregations.bucket.terms.InternalTerms.reduce(InternalTerms.java:37)  
> at  
> org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:146)  
> at  
> org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:386)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.innerFinishHim(TransportSearchQueryThenFetchAction.java:152)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.finishHim(TransportSearchQueryThenFetchAction.java:139)  
> ... 6 more
> 
> Here are the gists used to create the data:
> 
> - mapping : [Denormalized mapping · GitHub](https://gist.github.com/stephlag/f9402c699374438c3ede)
> - data: [Denormalized Input · GitHub](https://gist.github.com/stephlag/ecb5b2dc384a3f07602d)
> - queries: [top hits aggregation on denormalized data · GitHub](https://gist.github.com/stephlag/7ad8edf1ab6b757be3b3)
> 
> Le vendredi 23 mai 2014 18:05:18 UTC+2, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) a écrit :
> 
> > Thank you  
> > I see this pull request is now merged on the 1.3 branch so I will try  
> > this feature to see if it fits our needs.
> > 
> > Le vendredi 23 mai 2014 15:49:51 UTC+2, Adrien Grand a écrit :
> > 
> > > 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 ([Add top\_hits aggregation by martijnvg · Pull Request #6124 · elastic/elasticsearch · GitHub](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, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) 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](http://Elasticsearch.com)_  
> > > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > > > 
> > > > > Le 23 mai 2014 à 14:35:19, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) ([slagr...@ippon.fr](mailto:slagr...@ippon.fr)) a  
> > > > > écrit:
> > > > > 
> > > > > Hello,  
> > > > > I'm trying to use the new feature described here:  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/referenc)  
> > > > > e/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 : [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/g)  
> > > > > uide/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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > 
> > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%40goo  
> > > > > [glegroups.com](http://glegroups.com)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > msgid/elasticsearch/e24a0b30-dfea-4a2d-8591-4102fbafcc15%  
> > > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/e24a0b30-dfea-4a2d-8591-4102fbafcc15%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Met vriendelijke groet,

Martijn van Groningen

--  
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/CA%2BA76TzTDwv8W4Mv%3DVB%3DfK7kPPUrL%2BMZGwzxCU\_Tb9td9B6SMw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CA%2BA76TzTDwv8W4Mv%3DVB%3DfK7kPPUrL%2BMZGwzxCU_Tb9td9B6SMw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)
#### Post date: [May 30, 2014, 10:43am UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-parsing-error/17692/8 "2014-05-30T10:43:21Z")

</div>

Hi Stephan,

The bug has been fixed, can you try out a new build?

Martijn

On 30 May 2014 09:45, Martijn v Groningen [martijn.v.groningen@gmail.com](mailto:martijn.v.groningen@gmail.com)  
wrote:

> This is indeed a bug, thanks for sharing it! This should be easy to fix.
> 
> On 27 May 2014 11:35, [slagraulet@ippon.fr](mailto:slagraulet@ippon.fr) wrote:
> 
> > Hello,  
> > I tried the new top\_hots aggregation and made it work on denormalized  
> > data.
> > 
> > However, when I tries to add a filter I ran into the following exception:
> > 
> > [2014-05-27 11:32:12,869][DEBUG][action.search.type] [Cap 'N Hawk]  
> > failed to reduce search  
> > org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
> > execute phase [fetch], [reduce]  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.finishHim(TransportSearchQueryThenFetchAction.java:141)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction$1.onResult(TransportSearchQueryThenFetchAction.java:113)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction$1.onResult(TransportSearchQueryThenFetchAction.java:107)  
> > at  
> > org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:526)  
> > at  
> > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
> > at  
> > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
> > at java.lang.Thread.run(Thread.java:745)  
> > Caused by: java.lang.NullPointerException  
> > at  
> > org.apache.lucene.search.TopDocs$ScoreMergeSortQueue.(TopDocs.java:89)  
> > at org.apache.lucene.search.TopDocs.merge(TopDocs.java:219)  
> > at org.apache.lucene.search.TopDocs.merge(TopDocs.java:209)  
> > at  
> > org.elasticsearch.search.aggregations.bucket.tophits.InternalTopHits.reduce(InternalTopHits.java:107)  
> > at  
> > org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:146)  
> > at  
> > org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregation.reduce(InternalSingleBucketAggregation.java:82)  
> > at  
> > org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:146)  
> > at  
> > org.elasticsearch.search.aggregations.bucket.terms.InternalTerms$Bucket.reduce(InternalTerms.java:77)  
> > at  
> > org.elasticsearch.search.aggregations.bucket.terms.InternalTerms.reduce(InternalTerms.java:157)  
> > at  
> > org.elasticsearch.search.aggregations.bucket.terms.InternalTerms.reduce(InternalTerms.java:37)  
> > at  
> > org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:146)  
> > at  
> > org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:386)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.innerFinishHim(TransportSearchQueryThenFetchAction.java:152)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.finishHim(TransportSearchQueryThenFetchAction.java:139)  
> > ... 6 more
> > 
> > Here are the gists used to create the data:
> > 
> > - mapping : [Denormalized mapping · GitHub](https://gist.github.com/stephlag/f9402c699374438c3ede)
> > - data: [Denormalized Input · GitHub](https://gist.github.com/stephlag/ecb5b2dc384a3f07602d)
> > - queries: [top hits aggregation on denormalized data · GitHub](https://gist.github.com/stephlag/7ad8edf1ab6b757be3b3)
> > 
> > Le vendredi 23 mai 2014 18:05:18 UTC+2, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) a écrit :
> > 
> > > Thank you  
> > > I see this pull request is now merged on the 1.3 branch so I will try  
> > > this feature to see if it fits our needs.
> > > 
> > > Le vendredi 23 mai 2014 15:49:51 UTC+2, Adrien Grand a écrit :
> > > 
> > > > 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 ([Add top\_hits aggregation by martijnvg · Pull Request #6124 · elastic/elasticsearch · GitHub](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, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) 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](http://Elasticsearch.com)_  
> > > > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > > > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > > > > 
> > > > > > Le 23 mai 2014 à 14:35:19, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) ([slagr...@ippon.fr](mailto:slagr...@ippon.fr)) a  
> > > > > > écrit:
> > > > > > 
> > > > > > Hello,  
> > > > > > I'm trying to use the new feature described here:  
> > > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/referenc)  
> > > > > > e/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 : [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/g)  
> > > > > > uide/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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > 
> > > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > > msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%40goo  
> > > > > > [glegroups.com](http://glegroups.com)  
> > > > > > [https://groups.google.com/d/msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > > msgid/elasticsearch/e24a0b30-dfea-4a2d-8591-4102fbafcc15%  
> > > > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > > > [https://groups.google.com/d/msgid/elasticsearch/e24a0b30-dfea-4a2d-8591-4102fbafcc15%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

--  
Met vriendelijke groet,

Martijn van Groningen

--  
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/CA%2BA76Tw5VGJuXF8hE4r98S3\_--qA8Eps8kvvZ2Of53-Y%3DDmVFw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CA%2BA76Tw5VGJuXF8hE4r98S3_--qA8Eps8kvvZ2Of53-Y%3DDmVFw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![slagraulet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/slagraulet/32/1481_2.png) [@slagraulet](https://discuss.elastic.co/u/slagraulet)
#### Post date: [June 4, 2014, 9:01am UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-parsing-error/17692/9 "2014-06-04T09:01:18Z")

</div>

I tried with this morning build and the filter aggregation now works on top  
of the top\_tag\_hits aggregation.  
We plan to thoroughly test this feature as we need it to be "feature  
complete".

Thank you.

Le vendredi 30 mai 2014 12:43:50 UTC+2, Martijn v Groningen a écrit :

> Hi Stephan,
> 
> The bug has been fixed, can you try out a new build?
> 
> Martijn
> 
> On 30 May 2014 09:45, Martijn v Groningen \<[martijn.v...@gmail.com](mailto:martijn.v...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > This is indeed a bug, thanks for sharing it! This should be easy to fix.
> > 
> > On 27 May 2014 11:35, \<[slagr...@ippon.fr](mailto:slagr...@ippon.fr) \<javascript:\>\> wrote:
> > 
> > > Hello,  
> > > I tried the new top\_hots aggregation and made it work on denormalized  
> > > data.
> > > 
> > > However, when I tries to add a filter I ran into the following exception:
> > > 
> > > [2014-05-27 11:32:12,869][DEBUG][action.search.type] [Cap 'N  
> > > Hawk] failed to reduce search  
> > > org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
> > > execute phase [fetch], [reduce]  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.finishHim(TransportSearchQueryThenFetchAction.java:141)  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction$1.onResult(TransportSearchQueryThenFetchAction.java:113)  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction$1.onResult(TransportSearchQueryThenFetchAction.java:107)  
> > > at  
> > > org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:526)  
> > > at  
> > > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
> > > at  
> > > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
> > > at java.lang.Thread.run(Thread.java:745)  
> > > Caused by: java.lang.NullPointerException  
> > > at  
> > > org.apache.lucene.search.TopDocs$ScoreMergeSortQueue.(TopDocs.java:89)  
> > > at org.apache.lucene.search.TopDocs.merge(TopDocs.java:219)  
> > > at org.apache.lucene.search.TopDocs.merge(TopDocs.java:209)  
> > > at  
> > > org.elasticsearch.search.aggregations.bucket.tophits.InternalTopHits.reduce(InternalTopHits.java:107)  
> > > at  
> > > org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:146)  
> > > at  
> > > org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregation.reduce(InternalSingleBucketAggregation.java:82)  
> > > at  
> > > org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:146)  
> > > at  
> > > org.elasticsearch.search.aggregations.bucket.terms.InternalTerms$Bucket.reduce(InternalTerms.java:77)  
> > > at  
> > > org.elasticsearch.search.aggregations.bucket.terms.InternalTerms.reduce(InternalTerms.java:157)  
> > > at  
> > > org.elasticsearch.search.aggregations.bucket.terms.InternalTerms.reduce(InternalTerms.java:37)  
> > > at  
> > > org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:146)  
> > > at  
> > > org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:386)  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.innerFinishHim(TransportSearchQueryThenFetchAction.java:152)  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.finishHim(TransportSearchQueryThenFetchAction.java:139)  
> > > ... 6 more
> > > 
> > > Here are the gists used to create the data:
> > > 
> > > - mapping : [Denormalized mapping · GitHub](https://gist.github.com/stephlag/f9402c699374438c3ede)
> > > - data: [Denormalized Input · GitHub](https://gist.github.com/stephlag/ecb5b2dc384a3f07602d)
> > > - queries: [top hits aggregation on denormalized data · GitHub](https://gist.github.com/stephlag/7ad8edf1ab6b757be3b3)
> > > 
> > > Le vendredi 23 mai 2014 18:05:18 UTC+2, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) a écrit :
> > > 
> > > > Thank you  
> > > > I see this pull request is now merged on the 1.3 branch so I will try  
> > > > this feature to see if it fits our needs.
> > > > 
> > > > Le vendredi 23 mai 2014 15:49:51 UTC+2, Adrien Grand a écrit :
> > > > 
> > > > > 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 ([Add top\_hits aggregation by martijnvg · Pull Request #6124 · elastic/elasticsearch · GitHub](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, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) 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](http://Elasticsearch.com)_  
> > > > > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > > > > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > > > > > 
> > > > > > > Le 23 mai 2014 à 14:35:19, [slagr...@ippon.fr](mailto:slagr...@ippon.fr) ([slagr...@ippon.fr](mailto:slagr...@ippon.fr)) a  
> > > > > > > écrit:
> > > > > > > 
> > > > > > > Hello,  
> > > > > > > I'm trying to use the new feature described here:  
> > > > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/referenc)  
> > > > > > > e/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 : [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/g)  
> > > > > > > uide/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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > > 
> > > > > > > To view this discussion on the web visit  
> > > > > > > [https://groups.google.com/d/msgid/elasticsearch/8e02b4aa-606](https://groups.google.com/d/msgid/elasticsearch/8e02b4aa-606)  
> > > > > > > a-477d-bb2a-e0e02ee9a7a9%[40googlegroups.com](http://40googlegroups.com)  
> > > > > > > [https://groups.google.com/d/msgid/elasticsearch/8e02b4aa-606a-477d-bb2a-e0e02ee9a7a9%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > > > msgid/elasticsearch/e24a0b30-dfea-4a2d-8591-4102fbafcc15%  
> > > > > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > > > > [https://groups.google.com/d/msgid/elasticsearch/e24a0b30-dfea-4a2d-8591-4102fbafcc15%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ffe90554-8a54-45e9-8ee9-9457ffd658bf%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .
> > > 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > Met vriendelijke groet,
> > 
> > Martijn van Groningen
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

--  
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/2a795c59-e8ff-40cd-a2ca-51a7a9ef5b64%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2a795c59-e8ff-40cd-a2ca-51a7a9ef5b64%40googlegroups.com).  
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:24am UTC](https://discuss.elastic.co/t/reverse-nested-aggregation-parsing-error/17692/10 "2017-07-06T01:24:46Z")

</div>


