Skip to content

Instantly share code, notes, and snippets.

@raphi
Created January 16, 2015 14:51
Show Gist options
  • Save raphi/2f00bc372f352f38b594 to your computer and use it in GitHub Desktop.
Save raphi/2f00bc372f352f38b594 to your computer and use it in GitHub Desktop.
Compute age from an ElasticSearch document date
def now = new Date()
def birthday = new Date(doc["birthdate"].value)
return Integer.parseInt(now.format("Y")) - Integer.parseInt(birthday.format("Y")) - (birthday > now ? 1 : 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment