diff --git a/occurrence-download/src/main/java/org/gbif/occurrence/download/file/common/SearchQueryProcessor.java b/occurrence-download/src/main/java/org/gbif/occurrence/download/file/common/SearchQueryProcessor.java index 2ae9e036b..1195b46d0 100644 --- a/occurrence-download/src/main/java/org/gbif/occurrence/download/file/common/SearchQueryProcessor.java +++ b/occurrence-download/src/main/java/org/gbif/occurrence/download/file/common/SearchQueryProcessor.java @@ -71,9 +71,11 @@ public void processQuery(DownloadFileWork downloadFileWork, Consumer resultHa // Calculates the amount of output records int nrOfOutputRecords = downloadFileWork.getTo() - downloadFileWork.getFrom(); + if (nrOfOutputRecords <= 0) { + return; + } try { - int recordCount = 0; // Creates a search request instance using the search request that comes in the fileJob SearchSourceBuilder searchSourceBuilder = createSearchQuery(downloadFileWork.getQuery()); @@ -90,8 +92,11 @@ public void processQuery(DownloadFileWork downloadFileWork, Consumer resultHa consume(searchResponse, resultHandler); SearchHit[] searchHits = searchResponse.getHits().getHits(); + // https://github.com/gbif/occurrence/issues/514 + if (searchHits.length == 0) { + break; + } recordCount += searchHits.length; - } } catch (IOException ex) { throw new RuntimeException(ex);