# Got exception "mapping must have index set to true" when index already set to true

**URL:** <https://discuss.elastic.co/t/got-exception-mapping-must-have-index-set-to-true-when-index-already-set-to-true/364874>\
**Category:** Elastic Search\
**Created:** [August 14, 2024, 12:56am UTC](https://discuss.elastic.co/t/got-exception-mapping-must-have-index-set-to-true-when-index-already-set-to-true/364874 "2024-08-14T00:56:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lu\_Fan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lu_fan/32/136768_2.png) [@Lu\_Fan](https://discuss.elastic.co/u/Lu_Fan)\
**Post date:** [August 14, 2024, 12:56am UTC](https://discuss.elastic.co/t/got-exception-mapping-must-have-index-set-to-true-when-index-already-set-to-true/364874/1 "2024-08-14T00:56:54Z")

</div>

I am new to vector search. I followed an example code which already set index to true, but got this error "mapping must have index set to true". My elastic is v8.7.1. I am doing these in Kibana's dev tools-\>console. The first two cmds succeeded. It failed when I click on the search.

```auto
PUT my-index
{
  "mappings": {
    "properties": {
      "price": {
        "type": "integer"
      },
      "title_vector": {
        "type": "dense_vector",
        "dims": 3,
        "index": true,                
        "similarity": "cosine",       
        "index_options": {
          "ef_construction": 128,
          "m": 24    
        }
      }
    }
  }
}

POST my-index/_bulk
{ "index": { "_id": "1" } }
{ "title_vector": [2.2, 4.3, 1.8], "price": 23}
{ "index": { "_id": "2" } }
{ "title_vector": [3.1, 0.7, 8.2], "price": 9}
{ "index": { "_id": "3" } }
{ "title_vector": [1.4, 5.6, 3.9], "price": 124}
{ "index": { "_id": "4" } }
{ "title_vector": [1.1, 4.4, 2.9], "price": 1457}

POST my-index/_search
{
  "fields": ["price"],
  "knn": {
    "field": "title_vector",
    "query_vector": [0.1, 3.2, 2.1],
    "k": 2,
    "num_candidates": 100
  }
}

```

The error is:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: to perform knn search on field [title_vector], its mapping must have [index] set to [true]",
        "index_uuid": "zsLHCUVCTn-FBbrxdFbkvA",
        "index": "my-index"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "dfs",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "my-index",
        "node": "KjuBaoRZQhuXHcLgY3t4IA",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: to perform knn search on field [title_vector], its mapping must have [index] set to [true]",
          "index_uuid": "zsLHCUVCTn-FBbrxdFbkvA",
          "index": "my-index",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "to perform knn search on field [title_vector], its mapping must have [index] set to [true]"
          }
        }
      }
    ]
  },
  "status": 400
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 14, 2024, 4:21am UTC](https://discuss.elastic.co/t/got-exception-mapping-must-have-index-set-to-true-when-index-already-set-to-true/364874/2 "2024-08-14T04:21:30Z")

</div>

Welcome!

Could you try with 8.15 to check if this is now fixed?

---

<div class="post-metadata">

**Author:** ![Lu\_Fan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lu_fan/32/136768_2.png) [@Lu\_Fan](https://discuss.elastic.co/u/Lu_Fan)\
**Post date:** [August 14, 2024, 4:30am UTC](https://discuss.elastic.co/t/got-exception-mapping-must-have-index-set-to-true-when-index-already-set-to-true/364874/3 "2024-08-14T04:30:43Z")

</div>

Will do, thanks!

---

<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:** [September 11, 2024, 4:31am UTC](https://discuss.elastic.co/t/got-exception-mapping-must-have-index-set-to-true-when-index-already-set-to-true/364874/4 "2024-09-11T04:31:20Z")

</div>

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