Here is my suggestion.
You first try to find the right query for your use case using the query DSL.
Here you probably want to use a bool
query with filter
or must
clauses.
If you can't write it by yourself, you can try the SQL Translate API.
Once you have the right query working, you can transform it to Java Code using the search API.
Have a look at QueryBuilders as well.
If you need help, please provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.
A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.
A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case.