I have a database of books written by various authors. I would like to query books based on some attribute (say title text), and return ALL the books by each author for whom at least one of their books matches the search. For example, if author 1 writes books A, B, and C, and the query is for A, it should return A, B, and C.
I am planning on using a parent/child relation with author as the parent and books as the child. I see two possible approaches.
-
Query by author using has_child. Get the results of authors who have at least one book that matches the search. Then in a second query, get the list of books belonging to each of those authors.
-
Some type of nested has_parent -> has_child to get all the books whose author has a book that matches the search. This can be done in one query, but I am wondering if it is even faster than doing two separate queries.
Is there any significant performance difference between these approaches? I tried implementing both solutions and got them to work, but I don’t know enough about elasticsearch to decide which solution is better practice.
freezeflamegalaxy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.