# Potential bug in painless execute API since 7.5

**URL:** <https://discuss.elastic.co/t/potential-bug-in-painless-execute-api-since-7-5/242760>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 27, 2020, 2:07pm UTC](https://discuss.elastic.co/t/potential-bug-in-painless-execute-api-since-7-5/242760 "2020-07-27T14:07:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denne](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Denne](https://discuss.elastic.co/u/Denne)\
**Post date:** [July 27, 2020, 2:07pm UTC](https://discuss.elastic.co/t/potential-bug-in-painless-execute-api-since-7-5/242760/1 "2020-07-27T14:07:02Z")

</div>

I'm getting a strange error when using the painless execute API with cosineSimilarity. This only happens with version 7.5+. With version 7.4 this is not happening for me.

Here a minimal working example that uses the examples from the official documentation:

```auto
POST /_scripts/painless/_execute  
{  
  "script": {  
    "source": "cosineSimilarity(params.query_vector, 'query_vector') + 1.0",  
    "params": {  
      "query_vector": [3, 3.5, -0.1]  
    }  
  },  
  "context": "score",  
  "context_setup": {  
    "index": "my-index",  
    "document": {  
      "doc_vector": [4, 3.4, -0.2]  
    }  
  }  
}

```

Version used for this example: 7.8

Links to the documentation:  
[https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-execute-api.html](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-execute-api.html)  
[https://www.elastic.co/guide/en/elasticsearch/reference/7.8/query-dsl-script-score-query.html#\_dense\_vector\_functions](https://www.elastic.co/guide/en/elasticsearch/reference/7.8/query-dsl-script-score-query.html#_dense_vector_functions)

The exception I'm getting:

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "runtime error",
        "script_stack" : [
          "org.elasticsearch.script.ScoreScript._getIndexVersion(ScoreScript.java:204)",
          "org.elasticsearch.xpack.vectors.query.ScoreScriptUtils$DenseVectorFunction.getEncodedVector(ScoreScriptUtils.java:103)",
          "org.elasticsearch.xpack.vectors.query.ScoreScriptUtils$CosineSimilarity.cosineSimilarity(ScoreScriptUtils.java:179)",
          "cosineSimilarity(params.query_vector, 'skill_set_embedding') + 1.0",
          " ^---- HERE"
        ],
        "script" : "cosineSimilarity(params.query_vector, 'skill_set_embedding') + 1.0",
        "lang" : "painless",
        "position" : {
          "offset" : 38,
          "start" : 0,
          "end" : 66
        }
      }
    ],
    "type" : "script_exception",
    "reason" : "runtime error",
    "script_stack" : [
      "org.elasticsearch.script.ScoreScript._getIndexVersion(ScoreScript.java:204)",
      "org.elasticsearch.xpack.vectors.query.ScoreScriptUtils$DenseVectorFunction.getEncodedVector(ScoreScriptUtils.java:103)",
      "org.elasticsearch.xpack.vectors.query.ScoreScriptUtils$CosineSimilarity.cosineSimilarity(ScoreScriptUtils.java:179)",
      "cosineSimilarity(params.query_vector, 'skill_set_embedding') + 1.0",
      " ^---- HERE"
    ],
    "script" : "cosineSimilarity(params.query_vector, 'skill_set_embedding') + 1.0",
    "lang" : "painless",
    "position" : {
      "offset" : 38,
      "start" : 0,
      "end" : 66
    },
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "index version can not be looked up!"
    }
  },
  "status" : 400
}

```

Using the painless script in a normal search query works just fine. It only seems to be a problem when using the cosineSimilarity function in the painless execute API. I suspect it has something to do with the following MR which introduced the exception: [https://github.com/elastic/elasticsearch/pull/46294](https://github.com/elastic/elasticsearch/pull/46294)

Since the issue tracker on github mentions to first open a topic in the forum if the bug is not confirmed I only posted it here at the moment. If someone can replicate it I can open an issue on github for this.

---

<div class="post-metadata">

**Author:** ![Jack\_Conradson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_conradson/32/47236_2.png) [@Jack\_Conradson](https://discuss.elastic.co/u/Jack_Conradson)\
**Post date:** [July 30, 2020, 3:33pm UTC](https://discuss.elastic.co/t/potential-bug-in-painless-execute-api-since-7-5/242760/2 "2020-07-30T15:33:12Z")

</div>

Thank you for this great breakdown. It does look to indeed be the case that these methods were accidentally removed from the execute API. I agree they should be available in some form and will discuss with my team the best way to get them back in there.

---

<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:** [August 27, 2020, 3:33pm UTC](https://discuss.elastic.co/t/potential-bug-in-painless-execute-api-since-7-5/242760/3 "2020-08-27T15:33:12Z")

</div>

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