# How to change the "\_id" a couchdb doc is indexed under while using river

**URL:** https://discuss.elastic.co/t/how-to-change-the--id-a-couchdb-doc-is-indexed-under-while-using-river/11170
**Category:** Elasticsearch
**Created:** [March 15, 2013, 8:27pm UTC](https://discuss.elastic.co/t/how-to-change-the--id-a-couchdb-doc-is-indexed-under-while-using-river/11170 "2013-03-15T20:27:56Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![shadow](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@shadow](https://discuss.elastic.co/u/shadow)
#### Post date: [March 15, 2013, 8:27pm UTC](https://discuss.elastic.co/t/how-to-change-the--id-a-couchdb-doc-is-indexed-under-while-using-river/11170/1 "2013-03-15T20:27:56Z")

</div>

I know how to set up the river plugin and search across it. The problem is if the same document is edited multiple times (multiple revisions), the data from oldest revision is retained and older data is lost. I intend to be able keep an index all revisions for my entire couchdb.

For this my naive strategy is the following - create a new id which is a union of "\_id" and "\_rev" of the couchdb doc which comes through from the \_changes stream.

To accomplish, as per the docs, I tried the following:

What I did:

curl -XDELETE 127.0.0.1:9200/\_all  
curl -XPUT 'localhost:9200/foo\_test' -d '{  
"mappings": {  
"foo\_test": {  
"\_id": {  
"path": "newId",  
"index": "not\_analyzed",  
"store": "yes"  
}  
}  
}  
}'

curl -XPUT 'localhost: 9200/\_river/foo\_test/\_meta' -d '{  
"type": "couchdb",  
"couchdb": {  
"host": "127.0.0.1",  
"port": 5984,  
"db": "foo\_test",  
"script": "ctx.doc.newId = ctx.doc.\_id + ctx.doc.\_rev",  
"filter": null  
},  
"index": {  
"index": "foo\_test",  
"type": "foo\_test",  
"bulk\_size": "100",  
"bulk\_timeout": "10ms"  
}  
}'  
And after this, when I search for a doc I added, I get:

\_index: foo\_test  
\_type: foo\_test  
\_id: 53fa6fcf981a01b05387e680ac4a2efa  
\_score: 8.238497  
\_source: {  
\_rev: 4-8f8808f84eebd0984d269318ad21de93  
content: {  
foo: bar  
foo3: bar3  
foo2: bar2  
}  
\_id: 53fa6fcf981a01b05387e680ac4a2efa  
newId: 53fa6fcf981a01b05387e680ac4a2efa4-8f8808f84eebd0984d269318ad21de93

So I see that elasticsearch is not not using the new path to define its "\_id" field. Has anyone tried this before, or know what I might be doing wrong?

Also, I know its probably not wise to just keep storing all revs of the couchdb. I intend to figure out a way to delete really old revisions, but I guess that's for later.

Also, I did look into native "versioning" using elasticsearch - but that doesn't help me, as I intend to be able to access & search over previous versions and per what I have found "you can't do this using the builtin versioning. All that does is to store the current version number to prevent you applying updates out of order. "

---

<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:46am UTC](https://discuss.elastic.co/t/how-to-change-the--id-a-couchdb-doc-is-indexed-under-while-using-river/11170/2 "2017-07-06T02:46:15Z")

</div>


