# Update API can't find document

**URL:** <https://discuss.elastic.co/t/update-api-cant-find-document/325777>\
**Category:** Elasticsearch\
**Created:** [February 16, 2023, 8:53pm UTC](https://discuss.elastic.co/t/update-api-cant-find-document/325777 "2023-02-16T20:53:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![friaca](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/friaca/32/117373_2.png) [@friaca](https://discuss.elastic.co/u/friaca)\
**Post date:** [February 16, 2023, 8:53pm UTC](https://discuss.elastic.co/t/update-api-cant-find-document/325777/1 "2023-02-16T20:53:52Z")

</div>

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.

```auto
{
  "_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:

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

```

Which returns:

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

```

Then I tried removing the type:

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

```

Which returns:

```auto
{
  "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:

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

```

Which returns:

```auto
{
  "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

---

<div class="post-metadata">

**Author:** ![friaca](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/friaca/32/117373_2.png) [@friaca](https://discuss.elastic.co/u/friaca)\
**Post date:** [February 16, 2023, 9:37pm UTC](https://discuss.elastic.co/t/update-api-cant-find-document/325777/2 "2023-02-16T21:37:25Z")

</div>

Finally got it to update with `_update_by_query`.

```auto
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! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 16, 2023, 9:37pm UTC](https://discuss.elastic.co/t/update-api-cant-find-document/325777/3 "2023-03-16T21:37:52Z")

</div>

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