elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
1.34k stars 24.87k forks source link

Unable to update semantic text field in object using Update API #117258

Open Mikep86 opened 1 day ago

Mikep86 commented 1 day ago

Elasticsearch Version

8.15.x, 8.16.x, 8.17.x

Installed Plugins

No response

Java Version

bundled

OS Version

N/A

Problem Description

Under certain scenarios, you are unable to update a semantic text field using the Update API when the semantic text field is in an object field.

Steps to Reproduce

  1. Create an index with a semantic text field in an object:
PUT _inference/sparse_embedding/my-elser-endpoint
{
  "service": "elser",
  "service_settings": {
    "num_allocations": 1,
    "num_threads": 1
  }
}

PUT my-index
{
  "mappings": {
    "properties": {
      "object": {
        "properties": {
          "inference_field": {
            "type": "semantic_text",
            "inference_id": "my-elser-endpoint"
          }
        }
      }
    }
  }
}
  1. Add a document to the index, defining the semantic text field value using a nested structure
PUT my-index/_doc/doc1
{
  "object": {
    "inference_field": "test value"
  }
}
  1. Update the document using the Update API, defining the semantic text field value using a flat structure
POST my-index/_update/doc1
{
  "doc": { 
    "object.inference_field": "updated value"
  }
}

The update fails with the error:

{
    "error": {
        "root_cause": [
            {
                "type": "status_exception",
                "reason": "Invalid format for field [object.inference_field], expected [String] got [ArrayList]"
            }
        ],
        "type": "status_exception",
        "reason": "Invalid format for field [object.inference_field], expected [String] got [ArrayList]"
    },
    "status": 400
}

Logs (if relevant)

No response

elasticsearchmachine commented 1 day ago

Pinging @elastic/search-eng (Team:SearchOrg)

elasticsearchmachine commented 1 day ago

Pinging @elastic/search-relevance (Team:Search - Relevance)