I now title is long and confusing. Sorry for that. I have a book database in Elasticsearch 8.2.3 and records like:
{id:"1", "writer": "andy", "genre":"horror", "book_name":"first book of andy"}
{id:"2", "writer": "andy", "genre":"fantasy", "book_name":"second book of andy"}
{id:"3", "writer": "andy", "genre":"romance", "book_name":"thirth book of andy"}
{id:"4", "writer": "mike", "genre":"fantasy", "book_name":"first book of mike"}
{id:"5", "writer": "mike", "genre":"horror", "book_name":"second book of mike"}
{id:"6", "writer": "mike", "genre":"horror", "book_name":"thirth book of mike"}
{id:"7", "writer": "greg", "genre":"romance", "book_name":"first book of greg"}
{id:"8", "writer": "greg", "genre":"horror", "book_name":"second book of greg"}
{id:"9", "writer": "ursa", "genre":"romance", "book_name":"first book of ursa"}
{id:"10", "writer": "ursa", "genre":"fantasy", "book_name":"second book of ursa"}
I want a query that would return authors who have at least one book in both the "horror" and "fantasy" genres.
{"writer": "andy"}
{"writer": "mike"}
Also it would be great if it returns also the total number of books in these genres by these authors.
{"writer": "andy", "book_count": 2}
{"writer": "mike", "book_count": 3}
I can do it with multiple query and some coding with python but it is slow. If there is a way to do it with elsticsearch query I want to use it.