# Aggregations don't seem to work with template queries

**URL:** <https://discuss.elastic.co/t/aggregations-dont-seem-to-work-with-template-queries/20979>\
**Category:** Elasticsearch\
**Created:** [November 28, 2014, 11:37am UTC](https://discuss.elastic.co/t/aggregations-dont-seem-to-work-with-template-queries/20979 "2014-11-28T11:37:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luke\_Wilson\_Mawer](https://avatars.discourse-cdn.com/v4/letter/l/278dde/32.png) [@Luke\_Wilson\_Mawer](https://discuss.elastic.co/u/Luke_Wilson_Mawer)\
**Post date:** [November 28, 2014, 11:37am UTC](https://discuss.elastic.co/t/aggregations-dont-seem-to-work-with-template-queries/20979/1 "2014-11-28T11:37:26Z")

</div>

If I send a perfectly well formed aggregation query as a template query, I  
don't get the aggregation results.

[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-template-query.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-template-query.html)

Is this by design, or is there a workaround? I am using the Java query DSL  
and version 1.2.3.

Kind regards,

Luke

--  
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/960b74e9-4ef0-4e34-8b2d-e7c5dbf3930f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/960b74e9-4ef0-4e34-8b2d-e7c5dbf3930f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [November 28, 2014, 11:48am UTC](https://discuss.elastic.co/t/aggregations-dont-seem-to-work-with-template-queries/20979/2 "2014-11-28T11:48:10Z")

</div>

Hi Luke,

The page you linked to is for templating just the query section of a search  
request. To template the entire search request there is a dedicated  
endpoint described in the following link:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Let me know if this helps or not,

Colin

On Friday, 28 November 2014 11:37:26 UTC, Luke Wilson-Mawer wrote:

> If I send a perfectly well formed aggregation query as a template query, I  
> don't get the aggregation results.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-template-query.html)
> 
> Is this by design, or is there a workaround? I am using the Java query DSL  
> and version 1.2.3.
> 
> Kind regards,
> 
> Luke

--  
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/d16e23bb-cb65-4b43-bd1e-9d8b797e4f53%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d16e23bb-cb65-4b43-bd1e-9d8b797e4f53%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [November 28, 2014, 11:48am UTC](https://discuss.elastic.co/t/aggregations-dont-seem-to-work-with-template-queries/20979/3 "2014-11-28T11:48:40Z")

</div>

Sorry, this is the link I meant to attach:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Colin

On Friday, 28 November 2014 11:48:10 UTC, Colin Goodheart-Smithe wrote:

> Hi Luke,
> 
> The page you linked to is for templating just the query section of a  
> search request. To template the entire search request there is a dedicated  
> endpoint described in the following link:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-template.html)
> 
> Let me know if this helps or not,
> 
> Colin
> 
> On Friday, 28 November 2014 11:37:26 UTC, Luke Wilson-Mawer wrote:
> 
> > If I send a perfectly well formed aggregation query as a template query,  
> > I don't get the aggregation results.
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-template-query.html)
> > 
> > Is this by design, or is there a workaround? I am using the Java query  
> > DSL and version 1.2.3.
> > 
> > Kind regards,
> > 
> > Luke

--  
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/f222c11f-8f67-408d-9ed3-d388ce6ac5cc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f222c11f-8f67-408d-9ed3-d388ce6ac5cc%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Luke\_Wilson\_Mawer](https://avatars.discourse-cdn.com/v4/letter/l/278dde/32.png) [@Luke\_Wilson\_Mawer](https://discuss.elastic.co/u/Luke_Wilson_Mawer)\
**Post date:** [November 28, 2014, 4:01pm UTC](https://discuss.elastic.co/t/aggregations-dont-seem-to-work-with-template-queries/20979/4 "2014-11-28T16:01:47Z")

</div>

Hi Colin,

Thanks Colin. This does seem like it's the problem. I am building the query  
with the java query DSL but it seems to just stick the whole thing into the  
query section.

TemplateQueryBuilder qb = new TemplateQueryBuilder(myQueryString, myParams)

SearchResponse resp = client.prepareSearch(index).setQuery(qb  
).execute().actionGet();

Any idea how to get the Java API to point to the template endpoint?

Luke

On Friday, 28 November 2014 11:48:10 UTC, Colin Goodheart-Smithe wrote:

> Hi Luke,
> 
> The page you linked to is for templating just the query section of a  
> search request. To template the entire search request there is a dedicated  
> endpoint described in the following link:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-template.html)
> 
> Let me know if this helps or not,
> 
> Colin
> 
> On Friday, 28 November 2014 11:37:26 UTC, Luke Wilson-Mawer wrote:
> 
> > If I send a perfectly well formed aggregation query as a template query,  
> > I don't get the aggregation results.
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-template-query.html)
> > 
> > Is this by design, or is there a workaround? I am using the Java query  
> > DSL and version 1.2.3.
> > 
> > Kind regards,
> > 
> > Luke

--  
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/d13daac4-2092-4c87-b3d8-ef4c4a918337%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d13daac4-2092-4c87-b3d8-ef4c4a918337%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, 12:47am UTC](https://discuss.elastic.co/t/aggregations-dont-seem-to-work-with-template-queries/20979/5 "2017-07-06T00:47:10Z")

</div>


