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

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.

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:

{
  "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
}

Welcome!

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

Will do, thanks!

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