# \`document\_missing\_exception\` on Upsert?

**URL:** <https://discuss.elastic.co/t/document-missing-exception-on-upsert/82438>\
**Category:** Elasticsearch\
**Created:** [April 14, 2017, 6:28pm UTC](https://discuss.elastic.co/t/document-missing-exception-on-upsert/82438 "2017-04-14T18:28:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![skilledDeveloper](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skilleddeveloper/32/52979_2.png) [@skilledDeveloper](https://discuss.elastic.co/u/skilledDeveloper)\
**Post date:** [April 14, 2017, 6:28pm UTC](https://discuss.elastic.co/t/document-missing-exception-on-upsert/82438/1 "2017-04-14T18:28:36Z")

</div>

I use bulk update and have set `"doc_as_upsert": true`  
However, SOMETIMES I get errors like this:

```auto
"update": {
  "_index": "artists",
  "_type": "artist",
  "_id": "fernanda-francis",
  "status": 404,
  "error": {
  "type": "document_missing_exception",
  "reason": "[artist][fernanda-francis]: document missing",
  "index_uuid": "q123-ftoS4WD3eE1j0D0ka",
  "shard": "3",
  "index": "artists"
  }
}

```

Any ideas why this happens? Isn't it supposed to insert the doc if it doesn't exist?

ES v5.1 on AWS.

---

<div class="post-metadata">

**Author:** ![skilledDeveloper](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skilleddeveloper/32/52979_2.png) [@skilledDeveloper](https://discuss.elastic.co/u/skilledDeveloper)\
**Post date:** [April 17, 2017, 8:28pm UTC](https://discuss.elastic.co/t/document-missing-exception-on-upsert/82438/2 "2017-04-17T20:28:05Z")

</div>

Anyone has any ideas?  
Is this just me who has run into this issue?

---

<div class="post-metadata">

**Author:** ![mujtabahussain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mujtabahussain/32/17514_2.png) [@mujtabahussain](https://discuss.elastic.co/u/mujtabahussain)\
**Post date:** [April 20, 2017, 1:20am UTC](https://discuss.elastic.co/t/document-missing-exception-on-upsert/82438/3 "2017-04-20T01:20:55Z")

</div>

Hey @skilledDeveloper,

Any chance you could show us the upsert code?

---

<div class="post-metadata">

**Author:** ![skilledDeveloper](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skilleddeveloper/32/52979_2.png) [@skilledDeveloper](https://discuss.elastic.co/u/skilledDeveloper)\
**Post date:** [April 20, 2017, 5:51pm UTC](https://discuss.elastic.co/t/document-missing-exception-on-upsert/82438/4 "2017-04-20T17:51:09Z")

</div>

@mujtabahussain  
I use [elasticsearch npm package](https://www.npmjs.com/package/elasticsearch) and send something like the followings via `bulk` method:

```auto
  var artist = {...};
  var firstLine = {
    update: {
      _index: "artists",
      _type: "artist",
      _id: artist.id,
    }
  };
  var secondLine = {
    "doc": artist
    "doc_as_upsert": true
  };

  client.bulk({
    body: [firstLine, secondLine]
  }, function (err, resp) {
    // ...
  });

```

---

<div class="post-metadata">

**Author:** ![skilledDeveloper](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skilleddeveloper/32/52979_2.png) [@skilledDeveloper](https://discuss.elastic.co/u/skilledDeveloper)\
**Post date:** [May 3, 2017, 4:22pm UTC](https://discuss.elastic.co/t/document-missing-exception-on-upsert/82438/5 "2017-05-03T16:22:54Z")

</div>

Any ideas?

---

<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:** [May 31, 2017, 4:30pm UTC](https://discuss.elastic.co/t/document-missing-exception-on-upsert/82438/6 "2017-05-31T16:30:03Z")

</div>

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