Skip to main content

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