Inlining
How to denormalize related data, without additional query? Well, we can push normilized data to search and ask it to figure things out. This is done using scripted update of parent document. Does not require any effort from Postgres, while increasing a load on Elasticsearch.
N:M relations are not supported
And 1:1 do not make any sense in this context. Open issue if you need it.
In order to put one table as list of objects into another doc, you need to have parent key, which is usualy foreign key.
Imagine we have structire like thise.
So, having two tables users and comments with 1-N relationship, like
| Users | index:",all" inline:"user_comments,comments" |
|---|---|
| id (pk) | |
| name | |
| phone | index:"-" |
| Comments | index:"-" |
|---|---|
| id (pk) | inline:"user_comments" |
| user_id | inline:"user_comments,parent" |
| text | inline:"user_comments,content" |
| date |
here:
index:",all"comment on Users table means index all fields, withdocumentType={tablename}inline:"user_comments,comments"on Users table would inlineuser_commentsobjects intocommentsfield.index:"-"on a Users.phone would not index this field, regardlessindex:",all"on a table.index:"-"on Comments table, would not index this table entierly.inline:"user_comments"on Comments field id would include this field inuser_commentsinline, preserving field name. And since this column is PK, it would also be used as PK for inline.inline:"user_comments,parent"onuser_idwould specify PK of parrent document. So we can append comment into User.comments.inline:"user_comments,content"ontextfield id would include this field inuser_commentsinline under newcontentname.
and this would produce documents like
"_source": {
"docType": "users",
"id": 1631208,
"name": "Rick Sanchez",
"email": "rick@sanches.co",
"comments": [{
"id": 25285149,
"content": "Lorem Ipsum ...",
"user_id": 1631208
},{
"id": 25285753,
"content": "... dolore eu fugiat nulla pariatur...",
"user_id": 1631208
}]
}