# Comparison of two lists in Elsticsearch

**URL:** <https://discuss.elastic.co/t/comparison-of-two-lists-in-elsticsearch/248182>\
**Category:** Elasticsearch\
**Created:** [September 10, 2020, 1:43pm UTC](https://discuss.elastic.co/t/comparison-of-two-lists-in-elsticsearch/248182 "2020-09-10T13:43:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohitarorait82](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rohitarorait82/32/82981_2.png) [@rohitarorait82](https://discuss.elastic.co/u/rohitarorait82)\
**Post date:** [September 10, 2020, 1:43pm UTC](https://discuss.elastic.co/t/comparison-of-two-lists-in-elsticsearch/248182/1 "2020-09-10T13:43:44Z")

</div>

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  
}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 8, 2020, 1:43pm UTC](https://discuss.elastic.co/t/comparison-of-two-lists-in-elsticsearch/248182/2 "2020-10-08T13:43:56Z")

</div>

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