Execute scripted field on latest document instead of oldest?

Hi,

I have this scripted field that calculates the delay of incoming data. I'm made a table viz with unique count on the name field, the split it with a terms bucket for the name and a term for the delay below that. The goal is to show the latest document per name.

The problem I'm having is that the scripted field appears to be returning the calculation for the oldest field, but I want it executed on the newest field.

My data looks something like this

name: John
@original_ingest_time: 18:05

name: John
@original_ingest_time: 18:05

name: John
@original_ingest_time: 18:00

I tried many sorting options but its always returning results for the oldest document.

if (new Date().getTime() - doc['@original_ingest_time'].value.getMillis() >= 86400000) {
    return "High"
} else if (new Date().getTime() - doc['@original_ingest_time'].value.getMillis() >= 648000000) {
    return "Medium"
} else if (new Date().getTime() - doc['@original_ingest_time'].value.getMillis() >= 3600000) {
    return "Low"
} else if (new Date().getTime() - doc['@original_ingest_time'].value.getMillis() >= 0) {
    return "Normal"
}

Hi @Sjaak01,

Can you provide more details or a screen grab about the Metrics and Buckets you have created for your data table visualization? (dropdown values, etc) It does sound like a sorting problem somewhere.

Mike.

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