# Modifying documents in CouchDB river's script

**URL:** <https://discuss.elastic.co/t/modifying-documents-in-couchdb-rivers-script/5109>\
**Category:** Elasticsearch\
**Created:** [August 10, 2011, 10:17am UTC](https://discuss.elastic.co/t/modifying-documents-in-couchdb-rivers-script/5109 "2011-08-10T10:17:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petri\_Lehtinen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/petri_lehtinen/32/3145_2.png) [@Petri\_Lehtinen](https://discuss.elastic.co/u/Petri_Lehtinen)\
**Post date:** [August 10, 2011, 10:17am UTC](https://discuss.elastic.co/t/modifying-documents-in-couchdb-rivers-script/5109/1 "2011-08-10T10:17:27Z")

</div>

It's currently possible to modify the document in the CouchDB river's  
script. From documentation:

{  
"type" : "couchdb",  
"couchdb" : {  
"script" : "ctx.doc.field1 = 'value1'"  
}  
}

This works fine as long as the assigned value is a string. Trying to assign  
an array:

{  
"type" : "couchdb",  
"couchdb" : {  
"script" : "ctx.doc.field1 = ['value1', 'value2']"  
}  
}

In this case, field1 is assigned an obscure string representation of the  
array. I didn't try objects, but I'm assuming that all values are coerced to  
strings.

Is there any chance this could be fixed? If not, this should at least be  
documented.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 10, 2011, 11:45am UTC](https://discuss.elastic.co/t/modifying-documents-in-couchdb-rivers-script/5109/2 "2011-08-10T11:45:54Z")

</div>

This is a bug of not converting the resulting computation from the native  
javascript objects. Opened an issue:  
[CouchDB River: Custom script does not convert the modified doc properly to be indexed · Issue #1225 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1225).

On Wed, Aug 10, 2011 at 1:17 PM, Petri Lehtinen [petri@digip.org](mailto:petri@digip.org) wrote:

> It's currently possible to modify the document in the CouchDB river's  
> script. From documentation:
> 
> {  
> "type" : "couchdb",  
> "couchdb" : {  
> "script" : "ctx.doc.field1 = 'value1'"  
> }  
> }
> 
> This works fine as long as the assigned value is a string. Trying to assign  
> an array:
> 
> {  
> "type" : "couchdb",  
> "couchdb" : {  
> "script" : "ctx.doc.field1 = ['value1', 'value2']"  
> }  
> }
> 
> In this case, field1 is assigned an obscure string representation of the  
> array. I didn't try objects, but I'm assuming that all values are coerced to  
> strings.
> 
> Is there any chance this could be fixed? If not, this should at least be  
> documented.

---

<div class="post-metadata">

**Author:** ![Petri\_Lehtinen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/petri_lehtinen/32/3145_2.png) [@Petri\_Lehtinen](https://discuss.elastic.co/u/Petri_Lehtinen)\
**Post date:** [August 11, 2011, 10:27am UTC](https://discuss.elastic.co/t/modifying-documents-in-couchdb-rivers-script/5109/3 "2011-08-11T10:27:35Z")

</div>

Thanks for a fast fix.

---

<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, 3:57am UTC](https://discuss.elastic.co/t/modifying-documents-in-couchdb-rivers-script/5109/4 "2017-07-06T03:57:27Z")

</div>

Closed on July 6, 2017, 3:57am UTC


