From 81e4f1bbf06ed996bb880cc03e9ed1ba178a5dc1 Mon Sep 17 00:00:00 2001 From: PSeitz Date: Mon, 11 Mar 2024 04:54:55 +0100 Subject: [PATCH] handle track_total_size on request body (#4710) closes #4705 --- quickwit/quickwit-serve/src/elasticsearch_api/mod.rs | 2 +- .../quickwit-serve/src/elasticsearch_api/rest_handler.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/quickwit/quickwit-serve/src/elasticsearch_api/mod.rs b/quickwit/quickwit-serve/src/elasticsearch_api/mod.rs index a9a10a29761..0fdbd85c540 100644 --- a/quickwit/quickwit-serve/src/elasticsearch_api/mod.rs +++ b/quickwit/quickwit-serve/src/elasticsearch_api/mod.rs @@ -93,7 +93,7 @@ pub fn elastic_api_handlers( /// /// When set to `Count` with an integer value `n`, the response accurately tracks the total /// hit count that match the query up to `n` documents. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum TrackTotalHits { /// Track the number of hits that match the query accurately. diff --git a/quickwit/quickwit-serve/src/elasticsearch_api/rest_handler.rs b/quickwit/quickwit-serve/src/elasticsearch_api/rest_handler.rs index 2ba222238d1..e26ce41aaa2 100644 --- a/quickwit/quickwit-serve/src/elasticsearch_api/rest_handler.rs +++ b/quickwit/quickwit-serve/src/elasticsearch_api/rest_handler.rs @@ -269,7 +269,10 @@ fn build_request_for_es_api( let max_hits = search_params.size.or(search_body.size).unwrap_or(10); let start_offset = search_params.from.or(search_body.from).unwrap_or(0); - let count_hits = match search_params.track_total_hits { + let count_hits = match search_params + .track_total_hits + .or(search_body.track_total_hits) + { None => CountHits::Underestimate, Some(TrackTotalHits::Track(false)) => CountHits::Underestimate, Some(TrackTotalHits::Count(count)) if count <= max_hits as i64 => CountHits::Underestimate,