# How to overwrite docs with same id?

**URL:** <https://discuss.elastic.co/t/how-to-overwrite-docs-with-same-id/14384>\
**Category:** Elasticsearch\
**Created:** [November 13, 2013, 3:14pm UTC](https://discuss.elastic.co/t/how-to-overwrite-docs-with-same-id/14384 "2013-11-13T15:14:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![project2501](https://avatars.discourse-cdn.com/v4/letter/p/41988e/32.png) [@project2501](https://discuss.elastic.co/u/project2501)\
**Post date:** [November 13, 2013, 3:14pm UTC](https://discuss.elastic.co/t/how-to-overwrite-docs-with-same-id/14384/1 "2013-11-13T15:14:24Z")

</div>

Hi,  
I notice I cannot store a document and control the \_id field. It gives an  
error. I read that I need to 'enable' storing \_id?  
That is very odd.

I want to store a bunch of documents. And then I want to update ones by  
simply overwriting them with same \_id.  
I don't want to have to query to get an \_id, that is a waste of time.

How can this be done? Upsert? I need to control the \_id

thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![project2501](https://avatars.discourse-cdn.com/v4/letter/p/41988e/32.png) [@project2501](https://discuss.elastic.co/u/project2501)\
**Post date:** [November 13, 2013, 3:53pm UTC](https://discuss.elastic.co/t/how-to-overwrite-docs-with-same-id/14384/2 "2013-11-13T15:53:57Z")

</div>

Ok, I was able to find info on starting titan using titan.sh. The titan  
docs are pretty bad. Doesn't even tell you how to start the server (in the  
getting started page).

Anyway, once I did that. I now get this.

> > > from bulbs.titan import Graph  
> > > g = Graph()  
> > > james = g.vertices.create(name="James")  
> > > Traceback (most recent call last):  
> > > File "", line 1, in   
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/element.py", line 565,  
> > > in create  
> > > resp = self.client.create\_vertex(data)  
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/rexster/client.py",  
> > > line 370, in create\_vertex  
> > > return self.request.post(vertex\_path,data)  
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/rest.py", line 128, in  
> > > post  
> > > return self.request(POST, path, params)  
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/rest.py", line 183, in  
> > > request  
> > > return self.response\_class(http\_resp, self.config)  
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/rexster/client.py",  
> > > line 198, in **init**  
> > > self.handle\_response(response)  
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/rexster/client.py",  
> > > line 222, in handle\_response  
> > > response\_handler(http\_resp)  
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/rest.py", line 39, in  
> > > not\_found  
> > > raise LookupError(http\_resp)  
> > > LookupError: ({'status': '404', 'transfer-encoding': 'chunked', 'vary':  
> > > 'Accept', 'server': 'grizzly/2.2.16', 'date': 'Wed, 13 Nov 2013 15:51:54  
> > > GMT', 'access-control-allow-origin': '\*', 'content-type':  
> > > 'application/json;charset=ISO-8859-1'}, '{"message":"Graph [titanexample]  
> > > could not be found"}')

I realize that its probably my ignorance here, but the docs on both sides  
for this are pretty lean. I do appreciate the help.

On Wednesday, November 13, 2013 10:14:24 AM UTC-5, project2501 wrote:

> Hi,  
> I notice I cannot store a document and control the \_id field. It gives  
> an error. I read that I need to 'enable' storing \_id?  
> That is very odd.
> 
> I want to store a bunch of documents. And then I want to update ones by  
> simply overwriting them with same \_id.  
> I don't want to have to query to get an \_id, that is a waste of time.
> 
> How can this be done? Upsert? I need to control the \_id
> 
> thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![project2501](https://avatars.discourse-cdn.com/v4/letter/p/41988e/32.png) [@project2501](https://discuss.elastic.co/u/project2501)\
**Post date:** [November 13, 2013, 3:54pm UTC](https://discuss.elastic.co/t/how-to-overwrite-docs-with-same-id/14384/3 "2013-11-13T15:54:36Z")

</div>

Ok, I was able to find info on starting titan using titan.sh (on  
stackoverflow of all places). The titan docs are pretty bad. Doesn't even  
tell you how to start the server (in the getting started page).

Anyway, once I did that. I now get this.

> > > from bulbs.titan import Graph  
> > > g = Graph()  
> > > james = g.vertices.create(name="James")  
> > > Traceback (most recent call last):  
> > > File "", line 1, in   
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/element.py", line 565,  
> > > in create  
> > > resp = self.client.create\_vertex(data)  
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/rexster/client.py",  
> > > line 370, in create\_vertex  
> > > return self.request.post(vertex\_path,data)  
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/rest.py", line 128, in  
> > > post  
> > > return self.request(POST, path, params)  
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/rest.py", line 183, in  
> > > request  
> > > return self.response\_class(http\_resp, self.config)  
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/rexster/client.py",  
> > > line 198, in **init**  
> > > self.handle\_response(response)  
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/rexster/client.py",  
> > > line 222, in handle\_response  
> > > response\_handler(http\_resp)  
> > > File "/usr/local/lib/python2.7/dist-packages/bulbs/rest.py", line 39, in  
> > > not\_found  
> > > raise LookupError(http\_resp)  
> > > LookupError: ({'status': '404', 'transfer-encoding': 'chunked', 'vary':  
> > > 'Accept', 'server': 'grizzly/2.2.16', 'date': 'Wed, 13 Nov 2013 15:51:54  
> > > GMT', 'access-control-allow-origin': '\*', 'content-type':  
> > > 'application/json;charset=ISO-8859-1'}, '{"message":"Graph [titanexample]  
> > > could not be found"}')

I realize that its probably my ignorance here, but the docs on both sides  
for this are pretty lean. I do appreciate the help.

On Wednesday, November 13, 2013 10:14:24 AM UTC-5, project2501 wrote:

> Hi,  
> I notice I cannot store a document and control the \_id field. It gives  
> an error. I read that I need to 'enable' storing \_id?  
> That is very odd.
> 
> I want to store a bunch of documents. And then I want to update ones by  
> simply overwriting them with same \_id.  
> I don't want to have to query to get an \_id, that is a waste of time.
> 
> How can this be done? Upsert? I need to control the \_id
> 
> thanks.

On Wednesday, November 13, 2013 10:14:24 AM UTC-5, project2501 wrote:

> Hi,  
> I notice I cannot store a document and control the \_id field. It gives  
> an error. I read that I need to 'enable' storing \_id?  
> That is very odd.
> 
> I want to store a bunch of documents. And then I want to update ones by  
> simply overwriting them with same \_id.  
> I don't want to have to query to get an \_id, that is a waste of time.
> 
> How can this be done? Upsert? I need to control the \_id
> 
> thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [November 13, 2013, 6:05pm UTC](https://discuss.elastic.co/t/how-to-overwrite-docs-with-same-id/14384/4 "2013-11-13T18:05:41Z")

</div>

What do you mean by "controlling the \_id"? Using the index api, you need to  
send index, type and id (optional), plus the document itself as request  
body.  
If you so send the \_id, you can control what value you use for it,  
otherwise it's going to be auto-generated. In case it is auto0generated in  
order to overwrite an existing document you need to retrieve it and get its  
\_id back.

Does this help?

On Wednesday, November 13, 2013 4:14:24 PM UTC+1, project2501 wrote:

> Hi,  
> I notice I cannot store a document and control the \_id field. It gives  
> an error. I read that I need to 'enable' storing \_id?  
> That is very odd.
> 
> I want to store a bunch of documents. And then I want to update ones by  
> simply overwriting them with same \_id.  
> I don't want to have to query to get an \_id, that is a waste of time.
> 
> How can this be done? Upsert? I need to control the \_id
> 
> thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![project2501](https://avatars.discourse-cdn.com/v4/letter/p/41988e/32.png) [@project2501](https://discuss.elastic.co/u/project2501)\
**Post date:** [November 13, 2013, 9:40pm UTC](https://discuss.elastic.co/t/how-to-overwrite-docs-with-same-id/14384/5 "2013-11-13T21:40:51Z")

</div>

Hi Luca,

I try to set the '\_id' field, but it throws and error when I do. I did some  
searches about this but it's still not clear why I can't specify \_id.

Traceback (most recent call last):  
File "load-pyes.py", line 25, in   
conn.index('default','lexeme',entry,id=i)  
File "/usr/local/lib/python2.7/dist-packages/pyelasticsearch/client.py",  
line 96, in decorate  
return func(\*args, query\_params=query\_params, \*\*kwargs)  
File "/usr/local/lib/python2.7/dist-packages/pyelasticsearch/client.py",  
line 344, in index  
query\_params)  
File "/usr/local/lib/python2.7/dist-packages/pyelasticsearch/client.py",  
line 254, in send\_request  
self.\_raise\_exception(resp, prepped\_response)  
File "/usr/local/lib/python2.7/dist-packages/pyelasticsearch/client.py",  
line 269, in \_raise\_exception  
raise error\_class(response.status\_code, error\_message)  
pyelasticsearch.exceptions.ElasticHttpError: (400,  
u'MapperParsingException[failed to parse [\_id]]; nested:  
MapperParsingException[Provided id [1] does not match the content one  
[f5e638cc78dd325906c1298a0c21fb6b]]; ')

On Wednesday, November 13, 2013 1:05:41 PM UTC-5, Luca Cavanna wrote:

> What do you mean by "controlling the \_id"? Using the index api, you need  
> to send index, type and id (optional), plus the document itself as request  
> body.  
> If you so send the \_id, you can control what value you use for it,  
> otherwise it's going to be auto-generated. In case it is auto0generated in  
> order to overwrite an existing document you need to retrieve it and get its  
> \_id back.
> 
> Does this help?
> 
> On Wednesday, November 13, 2013 4:14:24 PM UTC+1, project2501 wrote:
> 
> > Hi,  
> > I notice I cannot store a document and control the \_id field. It gives  
> > an error. I read that I need to 'enable' storing \_id?  
> > That is very odd.
> > 
> > I want to store a bunch of documents. And then I want to update ones by  
> > simply overwriting them with same \_id.  
> > I don't want to have to query to get an \_id, that is a waste of time.
> > 
> > How can this be done? Upsert? I need to control the \_id
> > 
> > thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:07am UTC](https://discuss.elastic.co/t/how-to-overwrite-docs-with-same-id/14384/6 "2017-07-06T02:07:21Z")

</div>


