When dealing with entities that have many references, you might encounter the BooleanQuery.maxClauseCount which is 1024 by default. This value is already pretty high. But if a query exceeds this value, you should be aware that this is a warning indicator for your performance. 

A TermsQuery might be more appropriate in this case, looking somewhat like

 

result = result.filter(f.terms().field("entity_id").matchingAny(idList.stream().map(idToSearch -> String.valueOf(idToSearch)).collect(Collectors.toList())));