Update API can't find document

I'm trying to update a document field but had no success doing it. I can do a GET by ID with ticket-2/ticketelastic/134532 so that clarifies that the ID is valid and the document exists.

{
  "_index" : "ticket-2",
  "_type" : "ticketelastic",
  "_id" : "134532",
  "_version" : 637672165389810000,
  "_seq_no" : 183125,
  "_primary_term" : 2,
  "found" : true,
  "_source" : {
    //...
  }
}

I tried it with many methods I found online, such as:

POST ticket-2/ticketelastic/_update/134532
{
  "doc": {
    "status": 1
  }
}

Which returns:

{
  "error": "no handler found for uri [ticket-2/ticketelastic/_update/134532?pretty] and method [POST]"
}

Then I tried removing the type:

POST ticket-2/_update/134532
{
  "doc": {
    "status": 1
  }
}

Which returns:

{
  "error": {
    "root_cause": [
      {
        "type": "invalid_type_name_exception",
        "reason": "Document mapping type name can't start with '_', found: [_update]"
      }
    ],
    "type": "invalid_type_name_exception",
    "reason": "Document mapping type name can't start with '_', found: [_update]"
  },
  "status": 400
}

Then I tried to update with a script:

POST ticket-2/_doc/134532/_update
{
    "script" : "ctx._source.status = 1"
}

Which returns:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "document_missing_exception",
        "reason" : "[_doc][134532]: document missing",
        "index_uuid" : "0sWafHcDTYyYZQ2v7I_2UQ",
        "shard" : "0",
        "index" : "ticket-2"
      }
    ],
    "type" : "document_missing_exception",
    "reason" : "[_doc][134532]: document missing",
    "index_uuid" : "0sWafHcDTYyYZQ2v7I_2UQ",
    "shard" : "0",
    "index" : "ticket-2"
  },
  "status" : 404
}

Am I doing something wrong here? On my research I've seen people mention routing and whatnot, but that's not present on the metadata of my document, leading me to believe that routing is not necessary to specify. My Elasticsearch version is 6.6.1

1 Like

Finally got it to update with _update_by_query.

GET ticket-2/_update_by_query
{
  "query": {
    "term": {
      "_id": {
        "value": "134532"
      }
    }
  },
  "script" : "ctx._source.status = 1"
}

I still don't understand why the other methods didn't work when this one does basically the same thing. If someone sees this post and knows what I did wrong, please tell me so I can understand Elasticsearch a little bit more! :slight_smile:

1 Like

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