Hello,
Hierarchy:
parent {
child {
grandchild {
grandgrandchild {
....grandgrandgrandchildren
}
grandgrandchild {
....grandgrandgrandchild
}
}
}
}
User {
}
Rules:
User having access of partiuclar entity, will have automatic access to underlaying sub-entities
Non-super Users can be associated with grandgrandchild only
Super-users can be associated with parent
Access Patterns:
Search User in Parent by name
Get Users list by Parent
Get Users list by grandgrandchild
Search grandchild in child by name
Search grandgrandchild in grandchild by name
Get grandchild list by child
Get grandgrandchild list by grandchild
Index Design:
Creating indexes based on parentId and all children, grandchildren, grandgrandchildren, grandgrandgrandchild will be part of this index in linear fashion.
If there is a new parent, there will be a new index with same layout and so on.
I am duplicating Ids in each record. for example:
Get grandchild list by child:
each grandchild document will have field of "childId" and "entityType" like:
grandchild {
...matadata
childId: "<id>" // will be parent for this grandchild
entityType: "<grandchild>"
}
query: Get <parentId>/_search
{
"query": {
"query_string": {
"fields": [
"childId",
"entityType"
],
"query": "<childId> AND grandchild"
}
}
}
Nature of Application
Application is read intensive
Questions:
- Is this design good? It is inspired by single index design, I know it is not 100% fulfilling that but I tried to implement this.
- How can I achieve Get Users list by grandgrandchild because there is many to many relation and in Elasticsearch there is no such thing to resolve many to many relation as per my knowledge.
one possible solution I am thinking of is to keep array of userIds in each grandgrandchild or vice versa but I am not sure about the impact on performance because there will be 2 queries:
i. First query will get me all users ids (array) for particular grandgrandchild which i will supply to second query as input.
ii. Second query will get information information of each users based on the array.