How to create aging column for number of days wanted

hi can anyone share their experience in creating aging column?
the process is i need to calculate aging of days that a payment made between number of days invoice date - invoice due date

thank you for sharing

You can calculate the aging using Kibana scripted fields
So Basically you can a new scripted field called "aging_das" to your invoices index pattern then use this fiel to build a histogram based 30 days for example ...

Here is a snippet on how to add a scripted field on a DSL query, same painless code can be used in Kibana scripted field

GET invoices-payments/_search
  "_source": ["invoice_date", "due_date", "invoice_id"],  
  "script_fields": {
    "aging_days": {
      "script": {
        "source": "(doc['due_date'].value.toInstant().toEpochMilli() - doc['invoice_date'].value.toInstant().toEpochMilli()) / params.factor",
        "params": {
          "factor": 86400000

hi thanks for the shared script, but how can i add this script to the scripted field?

when i tried to add this snippet to scipted field on index patern it show errors
sorry im new to kibnana so a lot of alien things for me

Use only the content of the source like this

(doc['due_date'].value.toInstant().toEpochMilli() - doc['invoice_date'].value.toInstant().toEpochMilli()) / 86400000

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