2

I am trying to update a value in my index via java api using UpdateRequest which accepts three arguments.

  • Index
  • document
  • id

Question - I know what my index name is but i am not sure what value should be passed in document and id field.

SAMPLE DATA

{   
"took": 2,  
 "timed_out": false,   "_shards": {      "total": 5,      "successful": 5,      "failed": 0   },
   "hits": {
      "total": 1,
      "max_score": 0.94064164,
      "hits": [
         {
            "_index": "ticketdump",
            "_type": "event",
            "_id": "AVefK2vFmf0chKzzBkzy",
            "_score": 0.94064164,
            "_source": {
               "clientversion": "123465",
               "queue": "test,test",
               "vertical": "test",
               "troubleshooting": "test",
               "reason": "test",
               "status": "test",
               "ticketversion": "1132465",
               "apuid": 1,
               "golive": "2014-07-14",
               "clientname": "test",
               "message": "test",
               "product": "test",
               "clientid": 1,
               "createddatetime": "2016-05-03 09:43:48",
               "area": "test",
               "developmentfix": "test",
               "actiontaken": "test",
               "categoryname": "test",
               "parentcategory": "test",
               "problemdef": "test",
               "ticketid": 1
            }
         }
      ]
   }
}

I tried to pass _source object but it gave document missing error.Maybe I am missing the concept?

JAVA CODE

UpdateRequest updateRequest = new UpdateRequest(
  "ticketdump",
  js.getJSONObject("hits")
    .getJSONArray("hits")
    .getJSONObject(0)
    .getJSONObject("_source")
    .toString(),
  "1"
).script(new Script("ctx._source.message = \"bhavik\""));
client.update(updateRequest).get();

1 Answer 1

3

Actually, your UpdateRequest accepts 3 parameters

  1. Index
  2. Type
  3. Id

By the following data you can see that:

  1. Index = ticketdump
  2. Type = event
  3. Id = AVefK2vFmf0chKzzBkzy
Sign up to request clarification or add additional context in comments.

2 Comments

that worked. Thank you for your help and clarification.
after this answer was something changed in the JSON request? I might have a similar problem but I don't understand the issue here. A little help will be appreciated. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.