document missing exception while updating an index in elasticsearch via java api

14,762

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
Share:
14,762
Bhavik Patel
Author by

Bhavik Patel

B.tech in computer engineering.

Updated on June 16, 2022

Comments

  • Bhavik Patel
    Bhavik Patel almost 2 years

    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();
    
  • Bhavik Patel
    Bhavik Patel over 7 years
    that worked. Thank you for your help and clarification.
  • bogdan.rusu
    bogdan.rusu over 7 years
    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!