Age from year of birth

Sir,
I need to do a range aggeration for age ,from year of birth field.
How it possible .
Pls help

Hi Anand,
Welcome to the community.
you can try something like this

POST /your_index/_search?size=0
{
  "aggs": {
    "range": {
      "date_range": {
        "field": "date",
        "format": "MM-yyyy",
        "ranges": [
          { "to": "now/d" },  
          { "from": "date-of-birth" } 
        ]
      }
    }
  }
}

you need to change date-of-birth and provide your_index name . Also refer Date range aggregation | Elasticsearch Guide [8.0] | Elastic for more details

2 Likes

Thanks for your answer @DineshNaik . It help me a lot :clap: :clap: :clap: :palms_up_together: .

You are welcome!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.