From 57d4839af6a2e218b3ddb7e4d5f7c4c537866745 Mon Sep 17 00:00:00 2001 From: Patrick Leary Date: Thu, 7 Jul 2022 12:27:19 -0400 Subject: [PATCH] attempt to fix observer species count accuracy for small sizes #335 --- lib/controllers/v1/observations_controller.js | 5 +++++ 1 file changed, 5 insertions(+) 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;