Java High level rest client update

Hi All,

I m trying to update a nested field using java high level client .
Here i am using script to update the document . While executing it its throwing error which i have mentioned below.

CODE :

                    RestHighLevelClient esClient = new RestHighLevelClient(
			  RestClient.builder(new HttpHost("localhost",9200)));

                    UpdateRequest updateRequest = new UpdateRequest("my_index", "_doc", "1");
		
		Map<String, Object> parameters = new HashMap<String, Object>();
		
		parameters.put("key", "value or any java pojo");

		Script inline = new Script(ScriptType.INLINE, "painless",
		        "ctx._source.notes.add(params.key)", parameters);  
		updateRequest.script(inline);
		
		UpdateResponse updateResponse =  esClient.update(updateRequest);
		
		System.out.println("results : "+updateResponse.getId());
		
		esClient.close();

ERROR :

            ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=object mapping for [notes] tried to parse field [null] as object, but found a concrete value]]
at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177)
at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:653)
at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:628)
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:535)
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:508)
at org.elasticsearch.client.RestHighLevelClient.update(RestHighLevelClient.java:366)
at javasparkes.javaapi.JavaApi.main(JavaApi.java:59)
Suppressed: org.elasticsearch.client.ResponseException: method [POST], host[http://localhost:9200], URI [/my_index/_doc/1/_update?timeout=1m], status line [HTTP/1.1 400 Bad Request] {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"object mapping for [notes] tried to parse field [null] as object, but found a concrete value"}],"type":"mapper_parsing_exception","reason":"object mapping for [notes] tried to parse field [null] as object, but found a concrete value"},"status":400}
	at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:705)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:235)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:198)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:522)
	... 3 more

Anyone tried already/ facing the same issue. Please help , have been trying since three days but no solution till now.

Thank you all.

Have you tried running the same request using curl to understand whether it's a client issue or your request has something wrong in it?

Thanks for the response.
Yeah I have tried using Kibana. It's working fine.

cool can you please post the json request?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.