diff --git a/lib/controllers/v1/observations_controller.js b/lib/controllers/v1/observations_controller.js index c8b4c2e1..fad98c92 100644 --- a/lib/controllers/v1/observations_controller.js +++ b/lib/controllers/v1/observations_controller.js @@ -1219,6 +1219,11 @@ ObservationsController.observationsSpeciesObserverCounts = async req => { } } }; + // attempting to account for inaccurate counts for queries with a small size + // see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-shard-size + if ( ( ( aggSize * 1.5 ) + 10 ) < 50 ) { + countQuery.aggs.user_taxa.terms.shard_size = 50; + } } countQuery.per_page = 0; countQuery.skip_total_hits = true;