From 750d2acf7b592e5da12c2aa3125b50896349b069 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Sat, 11 Oct 2025 09:43:08 -0400 Subject: [PATCH] feat(config): Allow sending `track_total_hits` with ES query A few versions ago, Elasticsearch introduced an optimization where they only approximate the total hit count for a query (max of 10,000). It's of course nice to get better performance, but having hit count information is also super useful to examine queries for our own optimization. This change allows us to enable the [`track_total_hits`](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-search#operation-search-track_total_hits) flag on ES queries, with the similar `api.trackTotalHits` boolean in `pelias.json`. --- controller/search.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/controller/search.js b/controller/search.js index 3dbff74e7..992055246 100644 --- a/controller/search.js +++ b/controller/search.js @@ -59,6 +59,10 @@ function setup( peliasConfig, esclient, query, should_execute ){ cmd.explain = true; } + if (_.get(apiConfig, 'trackTotalHits') === true) { + cmd.track_total_hits = true; + } + // support for the 'clean.exposeInternalDebugTools' config flag let debugUrl; if (_.get(req, 'clean.exposeInternalDebugTools') === true) {