javaelasticsearchelasticsearch-painlesselasticsearch-java-apielasticsearch-scripting

Elasticsearch update nested field with painless script in ElasticSearch API vs java API


Could someone explain what's wrong with ES java api? I'm making query to update by script with ES api and it works perfectly (below)

POST user/ut/520411_5752/_update
{
  "script": {
    "source": "ctx._source.cars.add(params.car)",
    "params": {
      "car": {
        "pub_id":155,
        "name":"qwerty"
      }
    }
  }
}

and java

HashMap<String, Object> params = new HashMap<>();
params.put("car", GSON.toJson(car));

Script inline = new Script(ScriptType.INLINE, "painless",
"ctx._source.cars.add(params.car)", 
params);
    
UpdateRequest request = new UpdateRequest(USER, UT, id).script(inline).retryOnConflict(1);
UpdateResponse update = elasticClient.update(request, RequestOptions.DEFAULT);

As you may guess java is failing with exception

ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=object mapping for [cars] tried to parse field [null] as object, but found a concrete value]]

Tried different options, with empty car field, with filled car field, everytime getting an exception above.


Solution

  • Seems like i surrender with RestHighLevelClient. But i remember that i have LowLevelClient and rewrite my update using it and it's working fine. Since i don't need to check the response, i don't need to parse it too.