Skip to content

[BUG] Indices that include knn_vector field fail when search includes "fields" parameter #1633

Closed
@jmazanec15

Description

Description

Right now, for indices that contain a knn_vector, we are not able to support the fields option in queries. This is because in KNNVectorFieldType, we do not implement ValuesFetcher. We should implement it similar to the geo types that handle arrays directly.

curl -X GET "localhost:9200/target_index/_search?pretty" -H 'Content-Type: application/json' -d'
> {
>   "fields": ["*"],
>   "query": {
>     "match_all": {}
>   }
> }
> '

{
  "error" : {
    "root_cause" : [
      {
        "type" : "unsupported_operation_exception",
        "reason" : "KNN Vector do not support fields search"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "target_index",
        "node" : "grr7rDoPSwKXqQcpNrcbJQ",
        "reason" : {
          "type" : "unsupported_operation_exception",
          "reason" : "KNN Vector do not support fields search"
        }
      }
    ],
    "caused_by" : {
      "type" : "unsupported_operation_exception",
      "reason" : "KNN Vector do not support fields search",
      "caused_by" : {
        "type" : "unsupported_operation_exception",
        "reason" : "KNN Vector do not support fields search"
      }
    }
  },
  "status" : 500
}

Repro steps

curl -X PUT "localhost:9200/target_index" -H 'Content-Type: application/json' -d'
{
  "settings" : {
    "number_of_shards" : 1,
    "number_of_replicas" : 0,
    "index.knn": true
  },
  "mappings": {
       "properties": {
       "target_field": {
           "type": "knn_vector",
           "dimension": 2,
           "method": {
               "name":"hnsw",
               "engine":"nmslib",
               "space_type": "l2",
               "parameters":{
                 "m":20,
                 "ef_construction": 23
               }
           }
      }
   }
  }
}
'

curl -X PUT "localhost:9200/_bulk" -H 'Content-Type: application/json' -d'
{ "index": { "_index": "target_index" } }
{ "target_field": [1.5, 5.5]}
{ "index": { "_index": "target_index" } }
{ "target_field": [2.5, 3.5]}
{ "index": { "_index": "target_index" } }
{ "target_field": [4.5, 5.5]}
{ "index": { "_index": "target_index" } }
{ "target_field": [1.5, 5.5]}
{ "index": { "_index": "target_index" } }
{ "target_field": [1.5, 5.5]}
{ "index": { "_index": "target_index" } }
{ "target_field": [2.5, 3.5]}
'


curl localhost:9200/target_index/_refresh?pretty
curl -X GET "localhost:9200/target_index/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "fields": ["*"],
  "query": {
    "match_all": {}
  }
}
'

Metadata

Assignees

Labels

Type

No type

Projects

  • Status

    ✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions