# Birthday in Elasticsearch

**URL:** https://discuss.elastic.co/t/birthday-in-elasticsearch/132785
**Category:** Elasticsearch
**Created:** [May 22, 2018, 10:40am UTC](https://discuss.elastic.co/t/birthday-in-elasticsearch/132785 "2018-05-22T10:40:16Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![eedugon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eedugon/32/45404_2.png) [@eedugon](https://discuss.elastic.co/u/eedugon)
#### Post date: [May 22, 2018, 3:24pm UTC](https://discuss.elastic.co/t/birthday-in-elasticsearch/132785/2 "2018-05-22T15:24:48Z")

</div>

Hi @arpansahoo,

I guess that what you are trying to achieve is not that easy or straightforward.  
Please take a look to these resources and let me know your thoughts:

- In this topic you will be able to see my 2 favourite options to solve this:  
[Birthday Querying](https://discuss.elastic.co/t/birthday-querying/70684)

- This is also an interesting thread where a third option is explained:  
[Elasticsearch filtering by part of date - Stack Overflow](https://stackoverflow.com/questions/24010876/elasticsearch-filtering-by-part-of-date)

My suggestion would be to try to add a new field to your index called 'next\_birthday', calculated and daily updated via a periodic job, as @danielmitterdorfer was suggesting in the shared resource. If you can manage that, then your queries would be simple and straightforward.

About the data you are working with, and having a date field with format MMddyyyy || MMdd, I wouldn't recommend to keep dates with both year and without year provided in the same date-field, as I believe it won't be giving you any extra value (internally all dates will have a year attached, so, omitting the year in some documents you wouldn't be able to make sense out of the data).

In such case, I would recommend to store the fields separately, as it's suggested here:

> [@Elasticsearch date range queries with ignore year](https://discuss.elastic.co/t/elasticsearch-date-range-queries-with-ignore-year/46693):
>
> Hello everybody, I have a use case where I need to search in es for a date field. However, this is not only a simple range but I wanna ignore the year. Hence I saw this in the es docu: { "range" : { "born" : { "gte": "01/01/2012", "lte": "2013", "format": "dd/MM/yyyy||yyyy" } } } and I tried this: { "range" : { "born" : { "gte": "01/01", "lt": "02/01", "format": "dd/MM" } } } I had a document with a range date field which was set to 01.01.2014 but the above query didn't ma…

The third option mentioned before (storing as text and using wildcards in queries) could be valid if you don't have a big amount of users. Just keep an eye on the performance if you follow this approach.

Btw, how have you implemented the "search for exact birthday" query with your current data set?

Best regards,  
Eduardo

---

_[View the full topic](https://discuss.elastic.co/t/birthday-in-elasticsearch/132785)._
