# Can I create a histogram of ages based on birthdates?

**URL:** <https://discuss.elastic.co/t/can-i-create-a-histogram-of-ages-based-on-birthdates/17345>\
**Category:** Elasticsearch\
**Created:** [May 5, 2014, 10:34am UTC](https://discuss.elastic.co/t/can-i-create-a-histogram-of-ages-based-on-birthdates/17345 "2014-05-05T10:34:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ludwig\_Magnusson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ludwig_magnusson/32/1594_2.png) [@Ludwig\_Magnusson](https://discuss.elastic.co/u/Ludwig_Magnusson)\
**Post date:** [May 5, 2014, 10:34am UTC](https://discuss.elastic.co/t/can-i-create-a-histogram-of-ages-based-on-birthdates/17345/1 "2014-05-05T10:34:41Z")

</div>

Hello.  
I have an index populated with people and their birth dates. I want to  
create a histogram of their current ages. Is this possible?

So I have tried using a date histogram aggregation with year interval which  
gives me what years the users where born. This is a good start. To get  
exact ages I thought I could use the pre/post offset. Is this correct?  
I use the java client and calculate the number of milliseconds that have  
passes since the beginning of the year and pass that into the pre/post  
offset but I always get a null response when doing this. The entire request  
fails. If I remove the offsets the request passes again. Have I  
misunderstood something? Is it possible to use the date histogram to  
achieve what I want?

Thanks  
/Ludwig

--  
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/070a6e31-4e03-4899-b566-941012d0ae9b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/070a6e31-4e03-4899-b566-941012d0ae9b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)\
**Post date:** [May 5, 2014, 4:46pm UTC](https://discuss.elastic.co/t/can-i-create-a-histogram-of-ages-based-on-birthdates/17345/2 "2014-05-05T16:46:56Z")

</div>

This should be possible to do using script fields:

> **[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.

However, you will need to figure out how to do date manipulation there

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Mon, May 5, 2014 at 1:34 PM, Ludwig Magnusson \<[ludwig.magnusson@gmail.com](mailto:ludwig.magnusson@gmail.com)

> wrote:

> Hello.  
> I have an index populated with people and their birth dates. I want to  
> create a histogram of their current ages. Is this possible?
> 
> So I have tried using a date histogram aggregation with year interval  
> which gives me what years the users where born. This is a good start. To  
> get exact ages I thought I could use the pre/post offset. Is this correct?  
> I use the java client and calculate the number of milliseconds that have  
> passes since the beginning of the year and pass that into the pre/post  
> offset but I always get a null response when doing this. The entire request  
> fails. If I remove the offsets the request passes again. Have I  
> misunderstood something? Is it possible to use the date histogram to  
> achieve what I want?
> 
> Thanks  
> /Ludwig
> 
> --  
> 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/070a6e31-4e03-4899-b566-941012d0ae9b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/070a6e31-4e03-4899-b566-941012d0ae9b%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/070a6e31-4e03-4899-b566-941012d0ae9b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/070a6e31-4e03-4899-b566-941012d0ae9b%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/CAHTr4ZuiD-PvORm3Dgu3vOwD%2Bw3spc-X7jKLQC%2BkDrxFt4aeqg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZuiD-PvORm3Dgu3vOwD%2Bw3spc-X7jKLQC%2BkDrxFt4aeqg%40mail.gmail.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:31am UTC](https://discuss.elastic.co/t/can-i-create-a-histogram-of-ages-based-on-birthdates/17345/3 "2017-07-06T01:31:36Z")

</div>


