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?

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] De la part de Geert Pasteels
Envoyé : jeudi 9 février 2012 23:37
À : 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?

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.

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

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 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

Could you tell me if it fits to your needs ?

HTH

David.

De : elasticsearch@googlegroups.com [mailto:elasticsearch@googlegroups.com] De la part de Geert Pasteels
Envoyé : dimanche 12 février 2012 21:37
À : 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.

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.