# DocumentMissingException on bulk upsert

**URL:** https://discuss.elastic.co/t/documentmissingexception-on-bulk-upsert/41211
**Category:** Elasticsearch
**Created:** [February 8, 2016, 5:25pm UTC](https://discuss.elastic.co/t/documentmissingexception-on-bulk-upsert/41211 "2016-02-08T17:25:01Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jigish\_thakar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jigish_thakar/32/753_2.png) [@jigish\_thakar](https://discuss.elastic.co/u/jigish_thakar)
#### Post date: [February 8, 2016, 5:25pm UTC](https://discuss.elastic.co/t/documentmissingexception-on-bulk-upsert/41211/1 "2016-02-08T17:25:01Z")

</div>

Hi All,  
I am using ES 1.7  
also am using Python client for some particular type of data.

I need very small document to index  
{  
date : ....  
count: 1000  
}

every document will have some predefined id  
so below is the upsert command i am using (es python helper bulk)

{"\_id": "clientk1113120160208172000", "\_op\_type": "update", "\_type": "Count", "doc": {"script": "ctx.\_source.counter +=16", "upsert": {"counter": 16, "fdate": "2016-02-08T17:20:00"}}}

but its giving me below error

'1 document(s) failed to index.'  
[{  
u'update': {  
u'status': 404,  
u'\_type': u'Count',  
u'\_id': u'clientk1113120160208122000',  
u'error': u'DocumentMissingException[[clientk1113-rawlog-write][-1][Count][clientk1113120160208122000]: documentmissing]',  
u'\_index': u'clientk1113-rawlog-write'  
}  
}]

any help will be appreciated

Thanks

---

<div class="post-metadata">

### Author: ![abeyad](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@abeyad](https://discuss.elastic.co/u/abeyad)
#### Post date: [February 9, 2016, 5:39am UTC](https://discuss.elastic.co/t/documentmissingexception-on-bulk-upsert/41211/2 "2016-02-09T05:39:26Z")

</div>

One thing I noticed is that the document ID of your request does not match the document ID mentioned in your error response.

Second, for the upsert request, there is no outer "doc" element, see this example for how to formulate the JSON: [https://www.elastic.co/guide/en/elasticsearch/reference/2.0/docs-update.html#upserts](https://www.elastic.co/guide/en/elasticsearch/reference/2.0/docs-update.html#upserts)

---

<div class="post-metadata">

### Author: ![jigish\_thakar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jigish_thakar/32/753_2.png) [@jigish\_thakar](https://discuss.elastic.co/u/jigish_thakar)
#### Post date: [February 9, 2016, 8:24am UTC](https://discuss.elastic.co/t/documentmissingexception-on-bulk-upsert/41211/4 "2016-02-09T08:24:36Z")

</div>

yes it worked!  
{"\_op\_type":"update","\_type":"Count","\_id":"clientk1113120160122095000","script":"ctx.\_source.counter +=18802","upsert":{"counter":18802,"fdate":"2016-01-22T09:50:00"}}

---

<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: [July 5, 2017, 11:18pm UTC](https://discuss.elastic.co/t/documentmissingexception-on-bulk-upsert/41211/5 "2017-07-05T23:18:03Z")

</div>


