I have a set of docs (let's call them books), which have a subset of information (let's say editions), for a data structure somewhat akin to this:
"book": {
"author": "A. N. Author",
"title": "Fantastic Queries and How to Index Them"
"editions": [
{
"publisher":"penguin",
"isbn": 124161256653,
"coverArtist":"Pain T Brush",
"amazonPrice":65.50
},
{
"publisher":"orbit",
"isbn": 124163526653,
"coverArtist":"Pain T Brush",
"amazonPrice":25.99
},
{
"publisher":"tor",
"isbn": 124169876353,
"coverArtist":"Pen See Il",
"amazonPrice":700.00
}
]
}
Right now with the queries I have (which search on editions.publisher
or editions.isbn
), I get the whole document back, including editions that don't match the query results (I believe this is what's known as flattened/normalized data structure?). So, to be clear, if I search coverArtist
for Pain T Brush, the data I want returned is:
"book": {
"author": "A. N. Author",
"title": "Fantastic Queries and How to Index Them"
"editions": [
{
"publisher":"penguin",
"isbn": 124161256653,
"coverArtist":"Pain T Brush",
"amazonPrice":65.50
},
{
"publisher":"orbit",
"isbn": 124163526653,
"coverArtist":"Pain T Brush",
"amazonPrice":25.99
}
]
}
Same with the other queries. If I search for a specific isbn
, I only want its data to come back. If I set a price range of > 500
, I'd only want the last edition (along with the author and title information, of course). And finally, if I search for Fantastic Queries and How to Index Them
in the title, I want the whole doc returned, with all edition information, since I didn't specify anything edition-specific.
I was made aware of child and parent docs, in which each edition would be a child of one parent book. However, querying this system returns either a child or a parent, not both, which is what I need. Granted, if I get a child, its _parent
property can be used to GET
the parent's data, but that seems inefficient (i.e. I have to get two separate docs with two separate GET
requests; first the child result, then its parent).
So really, I wanted to double check here that I'm not missing some obvious solution. Is this parent-child doc structure the only way to achieve what I need, or is there something else I can use?