Comparison of two lists in Elsticsearch

Hi All,

I am new to ELK and facing issues with below scenario.

I am trying to compare two lists, listA and listB. This should provide a list of numbers which are present in listB but are not there in listA.

I have written below code for the same. However , the contains condition is not working here.

GET transform_temp/_search
{
"script_fields": {
"Account number": {
"script": {
"lang": "painless",
"source": """
List lista = new ArrayList();
List listb = new ArrayList();
List listfinal = new ArrayList();

          for(int j = 0; j < doc['Personal.keyword'].length; ++j) {
            if((doc['Personal.keyword'][j]).length() > 9){
             String d = (doc['Personal.keyword'][j].substring(2,10));
             lista.add(d);
            }
          }
           for(int j = 0; j < doc['Official.keyword'].length; ++j) {
            
             String d = doc['Official.keyword'][j];
             if(d !=""){
             listb.add(d);
            }
          }
          for (String x : listb){
            if (!lista.contains(x))
                listfinal.add(x);
              }
            return listfinal;
         """
  }
}

},
"size": 200
}