# CouchDB-river and related documents

**URL:** <https://discuss.elastic.co/t/couchdb-river-and-related-documents/6665>\
**Category:** Elasticsearch\
**Created:** [February 9, 2012, 10:37pm UTC](https://discuss.elastic.co/t/couchdb-river-and-related-documents/6665 "2012-02-09T22:37:14Z")\
**Posts on this page:** 6\
**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 9, 2012, 10:37pm UTC](https://discuss.elastic.co/t/couchdb-river-and-related-documents/6665/1 "2012-02-09T22:37:14Z")

</div>

I have a product which is owned by a user in my CouchDB.

product =  
name: 'Laptop'

user =  
username: 'James'

With views and include\_docs=true it returns:

product =  
name: 'Laptop'

user =  
username: 'James'

( I know it doesn't exactly return the above but it's close enough )

I do this cause every time I need a product I also need the owner (to link  
to his page). At first I thought I would just use include\_document=true on  
the \_change feed but of course that does something else.

So how can I get the related user when getting product results?

---

<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 10, 2012, 6:31pm UTC](https://discuss.elastic.co/t/couchdb-river-and-related-documents/6665/2 "2012-02-10T18:31:20Z")

</div>

Hi

I don’t understand what you are after ?

What are the JSON docs in couchDb and what do you want to get in ES ?

De : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com) [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] De la part de Geert Pasteels  
Envoyé : jeudi 9 février 2012 23:37  
À : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
Objet : CouchDB-river and related documents

I have a product which is owned by a user in my CouchDB.

product =

name: 'Laptop'

user =

username: 'James'

With views and include\_docs=true it returns:

product =

name: 'Laptop'

user =

```
username: 'James'

```

( I know it doesn't exactly return the above but it's close enough )

I do this cause every time I need a product I also need the owner (to link to his page). At first I thought I would just use include\_document=true on the \_change feed but of course that does something else.

So how can I get the related user when getting product results?

---

<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, 8:37pm UTC](https://discuss.elastic.co/t/couchdb-river-and-related-documents/6665/3 "2012-02-12T20:37:11Z")

</div>

In couchDb I have the following documents:

{  
\_id : "1234",  
name: "James",  
type : "user"  
}

{  
\_id : "5678"  
name : "snowboard"  
userId : "1234"  
type : "product"  
}

In couchDB I have a view to get documents with type 'product':

function(doc){  
if(doc.type === 'product'){  
emit(doc.\_id, { \_id: doc.userId, product: doc })  
}  
}

If I query that view with include\_docs=true it returns something like:

{  
value : {  
\_id : "5678"  
name : "snowboard"  
userId : "1234"  
type : "product"  
},  
doc: {  
\_id : "1234",  
name: "James",  
type : "user"  
}

}

The last result is what I would like to store in ES. So the product with  
it's user.

---

<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 12, 2012, 9:14pm UTC](https://discuss.elastic.co/t/couchdb-river-and-related-documents/6665/4 "2012-02-12T21:14:13Z")

</div>

So you are looking for view support in ES couchDb river ?

There is one pull request for that here : [https://github.com/elasticsearch/elasticsearch-river-couchdb/pull/2](https://github.com/elasticsearch/elasticsearch-river-couchdb/pull/2)

You can fork the code here [https://github.com/dadoonet/elasticsearch-river-couchdb/tree/dpi\_views](https://github.com/dadoonet/elasticsearch-river-couchdb/tree/dpi_views) [https://github.com/dadoonet/elasticsearch-river-couchdb/tree/dpi\_views](https://github.com/dadoonet/elasticsearch-river-couchdb/tree/dpi_views) build the river and test it to see if it answer to your needs.

Have a look at the README file here : [https://github.com/dadoonet/elasticsearch-river-couchdb/blob/dpi\_views/README.md](https://github.com/dadoonet/elasticsearch-river-couchdb/blob/dpi_views/README.md)

Could you tell me if it fits to your needs ?

HTH

David.

De : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com) [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] De la part de Geert Pasteels  
Envoyé : dimanche 12 février 2012 21:37  
À : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
Objet : Re: CouchDB-river and related documents

In couchDb I have the following documents:

{

\_id : "1234",

name: "James",

type : "user"

}

{

\_id : "5678"

name : "snowboard"

userId : "1234"

type : "product"

}

In couchDB I have a view to get documents with type 'product':

function(doc){

if(doc.type === 'product'){

```
emit(doc._id, { _id: doc.userId, product: doc })

```

}

}

If I query that view with include\_docs=true it returns something like:

{

value : {

```
_id : "5678"

name : "snowboard"

userId : "1234"

type : "product"

```

},

doc: {

```
_id : "1234",

name: "James",

type : "user"

```

}

}

The last result is what I would like to store in ES. So the product with it's user.

---

<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, 9:49pm UTC](https://discuss.elastic.co/t/couchdb-river-and-related-documents/6665/5 "2012-02-12T21:49:46Z")

</div>

Thanks David, that looks like it might work. I don't have a Java  
environment to compile it so I guess I have to wait a little. For now I am  
solving it by doing an extra query to couchDb.

---

<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-and-related-documents/6665/6 "2017-07-06T03:39:40Z")

</div>


