elasticsearch_dsl/search/params/
track_total_hits.rs

1/// Control how the total number of hits should be tracked.
2///
3/// When set to `Track` with a value `true`, the response will always track the number of hits that
4/// match the query accurately.
5///
6/// When set to `Count` with an integer value `n`, the response accurately tracks the total
7/// hit count that match the query up to `n` documents.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(untagged)]
10pub enum TrackTotalHits {
11    /// Whether to accurately track the number of hits that match the query accurately
12    Track(bool),
13
14    /// Accurately track the number of hits up to the specified value
15    Count(i64),
16}
17
18impl From<bool> for TrackTotalHits {
19    fn from(value: bool) -> Self {
20        TrackTotalHits::Track(value)
21    }
22}
23
24impl From<i64> for TrackTotalHits {
25    fn from(value: i64) -> Self {
26        TrackTotalHits::Count(value)
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33    use crate::util::*;
34
35    #[test]
36    fn serialization() {
37        assert_serialize(
38            [
39                TrackTotalHits::Track(false),
40                TrackTotalHits::Track(true),
41                TrackTotalHits::Count(10),
42            ],
43            json!([false, true, 10,]),
44        )
45    }
46}