# XOR on vector parameters

**URL:** <https://discuss.elastic.co/t/xor-on-vector-parameters/330368>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [April 20, 2023, 8:48am UTC](https://discuss.elastic.co/t/xor-on-vector-parameters/330368 "2023-04-20T08:48:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndtreviv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ndtreviv/32/22494_2.png) [@ndtreviv](https://discuss.elastic.co/u/ndtreviv)\
**Post date:** [April 20, 2023, 8:48am UTC](https://discuss.elastic.co/t/xor-on-vector-parameters/330368/1 "2023-04-20T08:48:41Z")

</div>

Hi,

I want to do an xor on vectors in a painless scoring script.  
ATM I'm iterating over one vector and xoring each entry with the corresponding entry in the query vector.  
Is there a way I can do it in a single command?

For example, I'm doing this now:

```auto
"script_score": {
        "script": {
          "lang": "painless",
          "source": "def c = 0; def dist = params._source['vector']) { dist += (dim^params.vector[c]); c++; if (dist > 32) { break; } } return 256 - dist;",
          "params": {
              "vector": [0, 1, 0, 1, 0, 0,..., 1, 0, 0, 1, 0, 0, 1, 0]
          }
        }
      }

```

Is something like this possible instead:

```auto
"script_score": {
        "script": {
          "lang": "painless",
          "source": "return 256 - params._source['vector']^params.vector;",
          "params": {
              "vector": [0, 1, 0, 1, 0, 0,..., 1, 0, 0, 1, 0, 0, 1, 0]
          }
        }
      }

```

---

<div class="post-metadata">

**Author:** ![ndtreviv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ndtreviv/32/22494_2.png) [@ndtreviv](https://discuss.elastic.co/u/ndtreviv)\
**Post date:** [April 20, 2023, 9:29am UTC](https://discuss.elastic.co/t/xor-on-vector-parameters/330368/2 "2023-04-20T09:29:32Z")

</div>

Would this be possible if I represented the vector (which is binary) as a binary data type?

---

<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:** [May 18, 2023, 9:30am UTC](https://discuss.elastic.co/t/xor-on-vector-parameters/330368/3 "2023-05-18T09:30:26Z")

</div>

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