Create a new field using painless

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.