How to get date now() function in Elasticsearch version 7.17.0

// Check if 'transactionTime' and 'transactionAmount' fields exist
if (!doc.containsKey('transactionTime') || doc['transactionTime'].size() == 0 || 
    !doc.containsKey('transactionAmount') || doc['transactionAmount'].size() == 0) {
    return 0; // Return 0 if either field is missing or empty
}

// Get current date
def now = new Date();

// Extract year and month from current date
def currentYear = now.getYear();
def currentMonth = now.getMonth();

// Get transaction date
def transactionDate = new Date(doc['TransactionTransmissionDateTime_NEW_UTC'].value);

// Check if the transaction is within the current month and year
if (transactionDate.getYear() == currentYear && transactionDate.getMonth() == currentMonth) {
    // Return transaction amount if it's within the current month
    return doc['TransactionAmount'].value;
} else {
    return 0; // Return 0 if transaction is not within the current month
}

Example one

def month = doc['timestamp'].value.monthOfYear;

def months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; 

return months[month-1];

I cant run any of these script in my cluster can you help me

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