Skip to content

Update API does not replace fields with sparse_vector field #135626

@spinscale

Description

@spinscale

Elasticsearch Version

9.1.4

Installed Plugins

No response

Java Version

bundled

OS Version

osx

Problem Description

When using the update API on a sparse_vector field, the existing contents of that field do not get removed, but the new data simply gets appended. This behaviour seems different from other fields, but makes sense from a JSON perspective.

I suppose the same issue is with rank_features, but the question is, if this is a bug or a feature.

Steps to Reproduce

DELETE alexr-test

PUT alexr-test
{
  "mappings": {
    "properties": {
      "sparse_vector": {
        "type": "sparse_vector"
      },
      "keyword" : {
        "type" : "keyword"
      }
    }
  }
}

PUT alexr-test/_doc/1?refresh
{
  "sparse_vector" : {
    "a" : 1,
    "b" : 2
  },
  "keyword": ["a", "b"]
}

POST alexr-test/_update/1?refresh
{
  "doc": {
    "sparse_vector" : {
      "c" : 3
    },
    "keyword" : ["c"]
  }
}

# this contains sparse_vector: { a:1, b:2, c:3 }
GET alexr-test/_doc/1

A workaround could be to use scripting

POST alexr-test/_update/1?refresh
{
  "script": {
    "params": {
      "sparse_vector": {
        "c": 3
      }
    },
    "source": "ctx._source.sparse_vector = params.sparse_vector"
  }
}

Logs (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions