# Writting aggregation queries in Elastic search

**URL:** <https://discuss.elastic.co/t/writting-aggregation-queries-in-elastic-search/18622>\
**Category:** Elasticsearch\
**Created:** [July 12, 2014, 1:57pm UTC](https://discuss.elastic.co/t/writting-aggregation-queries-in-elastic-search/18622 "2014-07-12T13:57:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Praveenkumar\_Arepall](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@Praveenkumar\_Arepall](https://discuss.elastic.co/u/Praveenkumar_Arepall)\
**Post date:** [July 12, 2014, 1:57pm UTC](https://discuss.elastic.co/t/writting-aggregation-queries-in-elastic-search/18622/1 "2014-07-12T13:57:35Z")

</div>

I want to achieve following query in elasticsearch.  
select max(creationDate - updatedDate) from sudentTable;

how to write above query?

elasticsearch verison is v1.1.1

select max(creationDate) from sudentTable; is writtren like below

public static void max() {  
final searchRequestBuilder builder = getClient().prepareSearch("indexname").  
setTypes("type1");  
MaxBuilder mx = AggregationBuilders.max("maxDate");  
mx.field("creationDate");  
builder.addAggregation(mx);  
System.out.print("builders:::"+builder);  
Aggregations ag = builder.execute().actionGet().getAggregations();  
InternalMax inMx = ag.get("maxDate");  
System.out.print("aggg::"+inMx.getValue()+"\n");  
}

--  
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/e0041d6c-5ce3-4aeb-88fb-cc3638a8cf6c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e0041d6c-5ce3-4aeb-88fb-cc3638a8cf6c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Praveenkumar\_Arepall](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@Praveenkumar\_Arepall](https://discuss.elastic.co/u/Praveenkumar_Arepall)\
**Post date:** [July 12, 2014, 6:29pm UTC](https://discuss.elastic.co/t/writting-aggregation-queries-in-elastic-search/18622/2 "2014-07-12T18:29:02Z")

</div>

[https://programmers.stackexchange.com/questions/249688/how-can-i-get-buckets-from-aggregation-querythis-is-belongs-to-elasticsearch](https://programmers.stackexchange.com/questions/249688/how-can-i-get-buckets-from-aggregation-querythis-is-belongs-to-elasticsearch)

Please check above question  
On Saturday, July 12, 2014 7:27:35 PM UTC+5:30, Praveenkumar Arepalli wrote:

> I want to achieve following query in elasticsearch.  
> select max(creationDate - updatedDate) from sudentTable;
> 
> how to write above query?
> 
> elasticsearch verison is v1.1.1
> 
> select max(creationDate) from sudentTable; is writtren like below
> 
> public static void max() {  
> final searchRequestBuilder builder = getClient().prepareSearch("indexname"  
> ).setTypes("type1");  
> MaxBuilder mx = AggregationBuilders.max("maxDate");  
> mx.field("creationDate");  
> builder.addAggregation(mx);  
> System.out.print("builders:::"+builder);  
> Aggregations ag = builder.execute().actionGet().getAggregations();  
> InternalMax inMx = ag.get("maxDate");  
> System.out.print("aggg::"+inMx.getValue()+"\n");  
> }

--  
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/e2c2418e-2fdb-49fc-b06c-b665f239c0a4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e2c2418e-2fdb-49fc-b06c-b665f239c0a4%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:16am UTC](https://discuss.elastic.co/t/writting-aggregation-queries-in-elastic-search/18622/3 "2017-07-06T01:16:16Z")

</div>


