and then all the correct rows seem to be included as well
The solution (which is not feasible, since meta data may expand to thousands of unique ID's) is adding NOT to all other existing terms:
$query =Contribute::searchByQuery(["query"=>["query_string"=>["query"=>"(grade=>'12' OR '10' NOT '8' NOT '9' NOT '11') AND (syllabus=>'IEB' NOT 'DOE') AND (meta_data=>'1' NOT '2' NOT '3' NOT '4' etc etc etc.)"]]],null,null, $paginate, $page);
So the question is, how do I exclude any terms, NOT specified, by default? Currently they just include themselves. In a simpler way than the second piece of code where I have to explicitly add what I don't want.
Btw, I build these queries from the user selection, so it is not as static as in these examples. Also, I find it pointless to do a database checkup to see what terms were not included, to be added to the query. Isn't the point of Elastic search to avoid doing db queries?