Scripted field using 2 metric aggregations

Hi,

Here's what I want to have in a DataTable visualization :

I'm using 2 aggregation metric fields :

  • 1 min to get the value of column Date1
  • 1 max to get the value of column Date2

For my third column, I would like to use the values that I get in both columns and do another script to calculate the values (it's the working days between the 2 dates)

Is there something like :
def mymin = aggregation on doc['time'].value; def mymax = aggregation on doc['time'].value; return mymax - mymin;

Hi @didinyah,

I think something like this should work:

def sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
def one = sdf.parse(doc["date1"].value.toString());
def two = sdf.parse(doc["date2"].value.toString());
return Math.abs(two.getTime() - one.getTime()) / (24 * 60 * 60 * 1000)

This should get you started but you might have to do a little more to handle only certain days (like working days) if that's what you want.

Let me know if that helps!

Thanks,
Chris

Hi, thanks for your answer.

I already managed to have the difference between 2 dates, the issue here is that "date1" and "date2" are the results of metric aggregations. I don't have these fields in my document, actually I'm using the same field to retrieve both of the dates, date1 is the min of this field and date2 is the max of this field.

This is how this is splitted in my kibana :
https://imgur.com/SEWnhiP

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