Ingest Pipeline: Compare two arrays with Painless Script

Hi everyone,

I'm working on an ingest pipeline in Elasticsearch where I have two array fields (alfa and beta), both populated by two different enrich processors earlier in the same pipeline. I would like to add a script processor using Painless to compare these two arrays and check if there is at least one matching value between them. If a match is found, the script should create a new field check with the value "Match". If no match is found, the value of check should be "No Match".

Additionally, I have some doubts about whether the fact that both arrays are populated by enrich processors earlier in the pipeline could cause issues. Could there be potential problems with data consistency or timing when working with enriched fields in this way? Any guidance or examples would be appreciated!

At the moment I try this:

if (ctx.alfa != null && ctx.beta != null) {
    boolean matchFound = false;
    
    // Loop through both arrays to check for at least one match
    for (String valueAlfa : ctx.alfa) {
        if (ctx.beta.contains(valueAlfa)) {
            matchFound = true;
            break;
        }
    }
    
    // Set the field 'check' based on whether a match was found
    if (matchFound) {
        ctx.check = 'Match';
    } else {
        ctx.check = 'No Match';
    }
} else {
    // Handle cases where one or both arrays are null
    ctx.check = 'Non Conforme';
}

Thank you for your help!