# Comparing lists in painless scripts

**URL:** <https://discuss.elastic.co/t/comparing-lists-in-painless-scripts/167833>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [February 11, 2019, 11:33am UTC](https://discuss.elastic.co/t/comparing-lists-in-painless-scripts/167833 "2019-02-11T11:33:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kanu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kanu/32/27148_2.png) [@kanu](https://discuss.elastic.co/u/kanu)\
**Post date:** [February 11, 2019, 11:33am UTC](https://discuss.elastic.co/t/comparing-lists-in-painless-scripts/167833/1 "2019-02-11T11:33:12Z")

</div>

Hi,

I am looking for an efficient way to compare the items of list.

```auto
PUT list_demo/doc/1
{
    "items": [1, 2, 3]
}

```

```auto
GET list_demo/_search
{
  "query": {
    "script": {
      "script": {
        "source": "(doc['items'].equals(params.items))",
        "params": {
          "items": [
            1,
            2,
            3
          ]
        }
      }
    }
  }
}

```

This query has no results.  
It seems that `doc['items']` is a list of Longs (even if mapped to integer) and `params.items` is an ArrayList containing Integers.

I was considering using the hashCode() method to compare both lists. This seems to find equal results, but does it guarantee to not return any false positives?

Are there any other ways to solve this?  
I don't speak Java.

Thx in advance

---

<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:** [March 11, 2019, 11:33am UTC](https://discuss.elastic.co/t/comparing-lists-in-painless-scripts/167833/2 "2019-03-11T11:33:57Z")

</div>

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