Has many relationship in couchdb

I'm using couchdb to store user data. Users can belong to an arbitrary
number of groups. Groups live in separate documents in couchdb. When I load
a user, I load the user document from couchdb, load a list of all of the
groups in the system, find the groups the user is associated with, and then
return the user document and its associated group documents to the
application layer for further processing. Here's an example of the two
types of documents:

User

{
"_id": "0c8cda925dd3f88a0d157e9c290013a4",
"_rev": "29-668e921b8f723f03188f60c44da24eaa",
"type": "user",
"disabled": false,
"username": "hoyt",
"firstName": "",
"lastName": "",
"emailAddress": "",
"roles": [
"user"
]
}

Group

{
"_id": "3979684300c58a4c90c7c6e0d6033dce",
"_rev": "60-9f88939a2e667766a7c49d501046beb8",
"type": "group",
"name": "test",
"description": "My description",
"users": [
"fbf8bc380b8cd64314bd7b4c65031d0d",
"0c8cda925dd3f88a0d157e9c290013a4"
]
}

I'm thinking of ways I can allow searching for all the users in a group by
group name in elastic search. For example, searching for 'test' would
return all users in the group with the name 'test'.

I'm planning on using the couchdb-river plugin and adding a script filter.
If it's possible, I suppose I could go through the same process in the
script filter, i.e. when the river receives notification that a user
document has changed it could query couch for a list of groups, find the
groups the user is associated with, and then store the group names as a
string field.

I've also looked at setting up a parent-child relationship in
elasticsearch, but that seems a little scary and I'm not sure if it will
work...:sunglasses:

Any advice on how to proceed is appreciated.

Thanks,

Troy

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Troy,

I think that I will probably try to have only Users in my ES index.
Because, in fact you seem to search for users, not for groups.

Can't you redesign a bit you data?

Something like:
{
"_id": "0c8cda925dd3f88a0d157e9c290013a4",
"_rev": "29-668e921b8f723f03188f60c44da24eaa",
"type": "user",
"disabled": false,
"username": "hoyt",
"firstName": "",
"lastName": "",
"emailAddress": "",
"roles": [
"user"
],
"groups": [
{ "name": "test", "description": "My description" }
]
}

Does it make sense and fit to your use case?
Why do you really need a group type?

HTH

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 26 févr. 2013 à 01:17, troy@scriptedmotion.com a écrit :

I'm using couchdb to store user data. Users can belong to an arbitrary number of groups. Groups live in separate documents in couchdb. When I load a user, I load the user document from couchdb, load a list of all of the groups in the system, find the groups the user is associated with, and then return the user document and its associated group documents to the application layer for further processing. Here's an example of the two types of documents:

User

{
"_id": "0c8cda925dd3f88a0d157e9c290013a4",
"_rev": "29-668e921b8f723f03188f60c44da24eaa",
"type": "user",
"disabled": false,
"username": "hoyt",
"firstName": "",
"lastName": "",
"emailAddress": "",
"roles": [
"user"
]
}

Group

{
"_id": "3979684300c58a4c90c7c6e0d6033dce",
"_rev": "60-9f88939a2e667766a7c49d501046beb8",
"type": "group",
"name": "test",
"description": "My description",
"users": [
"fbf8bc380b8cd64314bd7b4c65031d0d",
"0c8cda925dd3f88a0d157e9c290013a4"
]
}

I'm thinking of ways I can allow searching for all the users in a group by group name in Elasticsearch. For example, searching for 'test' would return all users in the group with the name 'test'.

I'm planning on using the couchdb-river plugin and adding a script filter. If it's possible, I suppose I could go through the same process in the script filter, i.e. when the river receives notification that a user document has changed it could query couch for a list of groups, find the groups the user is associated with, and then store the group names as a string field.

I've also looked at setting up a parent-child relationship in elasticsearch, but that seems a little scary and I'm not sure if it will work...:sunglasses:

Any advice on how to proceed is appreciated.

Thanks,

Troy

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.