1

I want to partially update a document in elastic search using java api. My ES mapping looks like :

"mappings": {

"DOC_TYPE": {
   "properties": {
        "FieldA": {
            "type": "long"
        },
        "FieldB": {
            "type": "long"
        },
        "FieldC": {
            "type": "long"
        }
  }

}

I want to update the value of FieldA. For the same I am using the following logic :

NOTE : map is containing the value to be updated. It is of type <String,Object>

UpdateRequest updateRequest = new UpdateRequest() .doc(map, XContentType.JSON);

Update.Builder builder = new Update.Builder(update).index("INDEX_NAME").type("DOC_TYPE").id("id");

client.execute(builder.build());

But I am getting error : {"error":{"root_cause":[{"type":"action_request_validation_exception","reason":"Validation Failed: 1: script or doc is missing;"}]

I am unable to figure out where I am going wrong as I have already added doc in my request.

NOTE : I am using JEST client here. Is it possible to partially update the document via Jest Client?

  • Which version of ES you are using, now ES supports official java client and Jest is not recommended and not available in latest versions of ES – Amit Jul 17 '20 at 05:16
  • Try `updateRequest = new UpdateRequest().index(indexName).type(type).id(id).doc(json);` All of type String – Gibbs Jul 17 '20 at 05:21
  • @OpsterElasticsearchNinja I am using 6.4 – Master Developer Jul 17 '20 at 06:45
  • @Gibbs the suggested method is throwing exception when doc(json) is executed. – Master Developer Jul 17 '20 at 06:46
  • @PiyushKumar curious to know why you are not using JLRC which was released in 6.0 only please refer https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.4/java-rest-high.html – Amit Jul 17 '20 at 06:53

0 Answers0