# Error while searching over dense vector

**URL:** <https://discuss.elastic.co/t/error-while-searching-over-dense-vector/358374>\
**Category:** Elastic Search\
**Tags:** painless\
**Created:** [April 28, 2024, 2:16pm UTC](https://discuss.elastic.co/t/error-while-searching-over-dense-vector/358374 "2024-04-28T14:16:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hiwora1211](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@hiwora1211](https://discuss.elastic.co/u/hiwora1211)\
**Post date:** [April 28, 2024, 2:16pm UTC](https://discuss.elastic.co/t/error-while-searching-over-dense-vector/358374/1 "2024-04-28T14:16:02Z")

</div>

Hello ,  
while doing query on my embedding field with this mapping 🙂

```auto
   "keywordsEmbedding": {
          "type": "dense_vector",
          "dims": 1536
        },

```

and this query :

```auto
GET /my_index/_search
{
"query": {
            "script_score": {
                "query": {
                    "bool": {
                        "filter": []
                    }
                },
                "script": {
                    "source": "cosineSimilarity(params.query_vector, doc['keywordsEmbedding'])",
                    "lang": "painless",
                    "params": {
                        "query_vector": [
            -0.010962439,
            -0.0069970214,

```

I ge the following error :

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "cosineSimilarity(params.query_vector, doc['keywordsEmbedding'])",
          " ^---- HERE"
        ],
        "script": "cosineSimilarity(params.query_vector, doc['keywordsEmbedding'])",
        "lang": "painless",
        "position": {
          "offset": 41,
          "start": 0,
          "end": 63
        }
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "my_index",
        "node": "tpn_abVVSPK-DGay7NJU8w",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "script_stack": [
            "cosineSimilarity(params.query_vector, doc['keywordsEmbedding'])",
            " ^---- HERE"
          ],
          "script": "cosineSimilarity(params.query_vector, doc['keywordsEmbedding'])",
          "lang": "painless",
          "position": {
            "offset": 41,
            "start": 0,
            "end": 63
          },
          "caused_by": {
            "type": "class_cast_exception",
            "reason": "cannot implicitly cast def [org.elasticsearch.index.mapper.vectors.DenseVectorScriptDocValues] to java.lang.String"
          }
        }
      }
    ]
  },
  "status": 400
}

```

what am I doing wrong ?  
thanks !

---

<div class="post-metadata">

**Author:** ![canelia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/canelia/32/141857_2.png) [@canelia](https://discuss.elastic.co/u/canelia)\
**Post date:** [April 29, 2024, 2:02am UTC](https://discuss.elastic.co/t/error-while-searching-over-dense-vector/358374/2 "2024-04-29T02:02:19Z")

</div>

try it.

```auto
GET /my_index/_search
{
"query": {
            "script_score": {
                "query": {
                    "bool": {
                        "filter": []
                    }
                },
                "script": {
                    "source": "cosineSimilarity(params.query_vector, 'keywordsEmbedding')",
                    "lang": "painless",
                    "params": {
                        "query_vector": [
            -0.010962439,
            -0.0069970214,

```

---

<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 27, 2024, 2:02am UTC](https://discuss.elastic.co/t/error-while-searching-over-dense-vector/358374/3 "2024-05-27T02:02:47Z")

</div>

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