# CouchDB-River deleted document

**URL:** <https://discuss.elastic.co/t/couchdb-river-deleted-document/6682>\
**Category:** Elasticsearch\
**Created:** [February 12, 2012, 10:46pm UTC](https://discuss.elastic.co/t/couchdb-river-deleted-document/6682 "2012-02-12T22:46:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geert\_Pasteels](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geert_pasteels/32/2994_2.png) [@Geert\_Pasteels](https://discuss.elastic.co/u/Geert_Pasteels)\
**Post date:** [February 12, 2012, 10:46pm UTC](https://discuss.elastic.co/t/couchdb-river-deleted-document/6682/1 "2012-02-12T22:46:56Z")

</div>

Hello,

I think I am missing something obvious but when I delete a CouchDb document  
the river doesn't seem to be picking up on the change.

This is how I create the river:

curl -XPUT 'localhost:9200/\_river/products/\_meta' -d '{  
"type" : "couchdb",  
"couchdb" : {  
"host" : "localhost",  
"port" : 5984,  
"db" : "fluf",  
"filter": "general/products"  
},  
"index" : {  
"index" : "products",  
"type" : "product",  
"bulk\_size" : "100",  
"bulk\_timeout" : "10ms"  
}  
}'

All my couchDb documents have a type field and the general/products filter  
will filter on type === 'product'. So is there something I am missing here?

Friendly Greetings,

Geert

---

<div class="post-metadata">

**Author:** ![Dan\_Everton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_everton/32/1865_2.png) [@Dan\_Everton](https://discuss.elastic.co/u/Dan_Everton)\
**Post date:** [February 13, 2012, 4:43am UTC](https://discuss.elastic.co/t/couchdb-river-deleted-document/6682/2 "2012-02-13T04:43:23Z")

</div>

When CouchDB deletes a document, the change event does not include the  
document. So if your filter function is something like:

return doc.type == 'product'

then it's filtering out the delete events. There's nothing that  
Elasticsearch can do in this case unfortunately. You just have to  
design around it by not filtering delete events.

See [https://github.com/elasticsearch/elasticsearch-river-couchdb/issues/7](https://github.com/elasticsearch/elasticsearch-river-couchdb/issues/7)  
for more discussion about this corner case.

Cheers,  
Dan

---

<div class="post-metadata">

**Author:** ![Geert\_Pasteels](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geert_pasteels/32/2994_2.png) [@Geert\_Pasteels](https://discuss.elastic.co/u/Geert_Pasteels)\
**Post date:** [February 13, 2012, 11:36am UTC](https://discuss.elastic.co/t/couchdb-river-deleted-document/6682/3 "2012-02-13T11:36:09Z")

</div>

Hello,

does it actually work if I remove the filter or do I have to do something  
else?

I read that issue a few times before but I guess I am not fully  
understanding it. If you delete something the change feed will show a  
delete message with the document id right? The document id is unique inside  
a couchdb database so couldn't you use that to delete it from the index or  
is it a problem if one elasticsearch instance is feeding of different  
couchDB databases so you can't be sure the id is unique?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 13, 2012, 11:45am UTC](https://discuss.elastic.co/t/couchdb-river-deleted-document/6682/4 "2012-02-13T11:45:39Z")

</div>

If you delete a document in couchDb, changes API will send the delete in stream and ES river will delete the document in ES as well.

HTH  
David 😉  
@dadoonet

Le 13 févr. 2012 à 12:36, Geert Pasteels [geert.pasteels@gmail.com](mailto:geert.pasteels@gmail.com) a écrit :

> Hello,
> 
> does it actually work if I remove the filter or do I have to do something else?
> 
> I read that issue a few times before but I guess I am not fully understanding it. If you delete something the change feed will show a delete message with the document id right? The document id is unique inside a couchdb database so couldn't you use that to delete it from the index or is it a problem if one elasticsearch instance is feeding of different couchDB databases so you can't be sure the id is unique?

---

<div class="post-metadata">

**Author:** ![Geert\_Pasteels](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geert_pasteels/32/2994_2.png) [@Geert\_Pasteels](https://discuss.elastic.co/u/Geert_Pasteels)\
**Post date:** [February 13, 2012, 11:52am UTC](https://discuss.elastic.co/t/couchdb-river-deleted-document/6682/5 "2012-02-13T11:52:47Z")

</div>

I just realized why it doesn't work with a filter I think. Cause the delete  
message doesn't show up in the changes feed if you filter it?

---

<div class="post-metadata">

**Author:** ![Dan\_Everton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_everton/32/1865_2.png) [@Dan\_Everton](https://discuss.elastic.co/u/Dan_Everton)\
**Post date:** [February 13, 2012, 9:55pm UTC](https://discuss.elastic.co/t/couchdb-river-deleted-document/6682/6 "2012-02-13T21:55:36Z")

</div>

CouchDB is sending the delete message but your filter function is  
preventing it from going to Elasticsearch.

I assume your filter function looks like this"

```
return doc.type == 'product'

```

Well that will filter out deleted document events because the only  
fields a deleted document as are \_id, \_rev, and \_deleted. By saying it  
must also have a type field, your filter is rejecting the delete  
event.

If you want the delete events to pass through your filter you need to  
do something like

```
return doc._deleted || doc.type == 'product'
```

---

<div class="post-metadata">

**Author:** ![Geert\_Pasteels](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geert_pasteels/32/2994_2.png) [@Geert\_Pasteels](https://discuss.elastic.co/u/Geert_Pasteels)\
**Post date:** [February 13, 2012, 10:01pm UTC](https://discuss.elastic.co/t/couchdb-river-deleted-document/6682/7 "2012-02-13T22:01:55Z")

</div>

That's a great solution Dan, thanks a bunch!

---

<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:39am UTC](https://discuss.elastic.co/t/couchdb-river-deleted-document/6682/8 "2017-07-06T03:39:34Z")

</div>


