Search code examples
elasticsearchelastic-stackelasticsearch-dsl

Unable to update a dense vector field through update API


I am trying to update a dense vector data in one of the es document and unable to update with error field not present in mapping, even when the field is present

Mapping:

{
  "sidx-4111c0fc-a8ba-523c-9851-34a2b803643b" : {
    "mappings" : {
      "properties" : {
       
        "dense_vector_field" : {
          "type" : "dense_vector",
          "dims" : 768
        },
       
        "searchResultPreview" : {
          "type" : "text",
          "fields" : {
            "search_result_preview" : {
              "type" : "keyword"
            }
          }
        }
      }
    }
  }

query -

POST /sidx-4111c0fc-a8ba-523c-9851-34a2b803643b/_update/xLVRVHUB3NwnlUUimDIR
{
  "dense_vector_field": [...]
}

Error:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "x_content_parse_exception",
        "reason" : "[2:3] [UpdateRequest] unknown field [dense_vector_field]"
      }
    ],
    "type" : "x_content_parse_exception",
    "reason" : "[2:3] [UpdateRequest] unknown field [dense_vector_field]"
  },
  "status" : 400
}

Am I missing something here?

Ignored mentioning vector data because of huge dimensions


Solution

  • The problem is that the _update API expects either a doc or a script, so you need to do it this way:

    POST /sidx-4111c0fc-a8ba-523c-9851-34a2b803643b/_update/xLVRVHUB3NwnlUUimDIR
    {
      "doc": {
        "dense_vector_field": [...]
      }
    }
    

    Or this way using a script:

    POST /sidx-4111c0fc-a8ba-523c-9851-34a2b803643b/_update/xLVRVHUB3NwnlUUimDIR
    {
      "script": {
        "source": "ctx._source.dense_vector_field = params.vector",
        "params": {
          "vector": [...]
        }
      } 
    }