Hello i want to convert my Date of Birth ("DateBirth") data to be Age data using scripted field.
So how it possible ? Can you tell me how to convert it ?
so this is my query:
Hello i want to convert my Date of Birth ("DateBirth") data to be Age data using scripted field.
So how it possible ? Can you tell me how to convert it ?
so this is my query:
Assuming that the BirthDate
field has been mapped as a date field, the following should work:
GET my_index/_search
{
"script_fields": {
"age": {
"script": {
"source": "if (doc['BirthDate'].size() != 0) { ChronoUnit.YEARS.between(doc['BirthDate'].value, Instant.ofEpochMilli(System.currentTimeMillis()).atZone(ZoneId.systemDefault())) }"
}
}
}
}
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
© 2020. All Rights Reserved - Elasticsearch
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant logo are trademarks of the Apache Software Foundation in the United States and/or other countries.