elasticsearch_dsl/search/params/
point_in_time.rs

1use super::Time;
2
3/// A point in time (PIT) is a point that represents a consistent view of the data at that time.
4#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
5pub struct PointInTime {
6    id: String,
7    keep_alive: Time,
8}
9
10impl PointInTime {
11    /// Creates a new instance of [`PointInTime`].
12    ///
13    /// - The `id` parameter tells Elasticsearch to execute the request using contexts from this point in time.
14    /// - The `keep_alive` parameter tells Elasticsearch how long it should extend the time to live of the point in time.
15    pub fn new<T>(id: T, keep_alive: Time) -> Self
16    where
17        T: ToString,
18    {
19        Self {
20            id: id.to_string(),
21            keep_alive,
22        }
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29    use crate::{util::assert_serialize, Search};
30
31    #[test]
32    fn adds_boolean() {
33        assert_serialize(
34            Search::new().pit(PointInTime::new("46ToAwMDaWR5BXV1aWQyKwZub2RlXzMAAAAAAAAAACoBYwADaWR4BXV1aWQxAgZub2RlXzEAAAAAAAAAAAEBYQADaWR5BXV1aWQyKgZub2RlXzIAAAAAAAAAAAwBYgACBXV1aWQyAAAFdXVpZDEAAQltYXRjaF9hbGw_gAAAAA", Time::Minutes(1))),
35            json!({
36                "pit": {
37                    "id": "46ToAwMDaWR5BXV1aWQyKwZub2RlXzMAAAAAAAAAACoBYwADaWR4BXV1aWQxAgZub2RlXzEAAAAAAAAAAAEBYQADaWR5BXV1aWQyKgZub2RlXzIAAAAAAAAAAAwBYgACBXV1aWQyAAAFdXVpZDEAAQltYXRjaF9hbGw_gAAAAA",
38                    "keep_alive": "1m"
39                }
40            }),
41        );
42    }
43}