protected SearchResponse filterMaxHits(SearchResponse response, int maxHits) {
// We will use internal APIs here for efficiency. The plugin has restricted explicit ES compatibility
// anyway. Alternatively, we could serialize/ filter/ deserialize JSON, but this seems simpler.
SearchHits allHits = response.getHits();
InternalSearchHit [] trimmedHits = new InternalSearchHit[Math.min(maxHits, allHits.hits().length)];
System.arraycopy(allHits.hits(), 0, trimmedHits, 0, trimmedHits.length);
InternalFacets facets = null;
if (response.getFacets() != null) {
facets = new InternalFacets(response.getFacets().facets());