diff --git a/src/search/params/mod.rs b/src/search/params/mod.rs index 6254fb1..d540c52 100644 --- a/src/search/params/mod.rs +++ b/src/search/params/mod.rs @@ -6,6 +6,7 @@ mod geo_distance_type; mod geo_location; mod geo_shape; mod number; +mod point_in_time; mod score_mode; mod script_sort_type; mod search_filter; @@ -22,6 +23,7 @@ pub use self::geo_distance_type::*; pub use self::geo_location::*; pub use self::geo_shape::*; pub use self::number::*; +pub use self::point_in_time::*; pub use self::score_mode::*; pub use self::script_sort_type::*; pub use self::search_filter::*; diff --git a/src/search/params/point_in_time.rs b/src/search/params/point_in_time.rs new file mode 100644 index 0000000..76acd36 --- /dev/null +++ b/src/search/params/point_in_time.rs @@ -0,0 +1,43 @@ +use super::Time; + +/// A point in time (PIT) is a point that represents a consistent view of the data at that time. +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +pub struct PointInTime { + id: String, + keep_alive: Time, +} + +impl PointInTime { + /// Creates a new instance of [`PointInTime`]. + /// + /// - The `id` parameter tells Elasticsearch to execute the request using contexts from this point in time. + /// - The `keep_alive` parameter tells Elasticsearch how long it should extend the time to live of the point in time. + pub fn new(id: T, keep_alive: Time) -> Self + where + T: ToString, + { + Self { + id: id.to_string(), + keep_alive, + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{util::assert_serialize, Search}; + + #[test] + fn adds_boolean() { + assert_serialize( + Search::new().pit(PointInTime::new("46ToAwMDaWR5BXV1aWQyKwZub2RlXzMAAAAAAAAAACoBYwADaWR4BXV1aWQxAgZub2RlXzEAAAAAAAAAAAEBYQADaWR5BXV1aWQyKgZub2RlXzIAAAAAAAAAAAwBYgACBXV1aWQyAAAFdXVpZDEAAQltYXRjaF9hbGw_gAAAAA", Time::Minutes(1))), + json!({ + "pit": { + "id": "46ToAwMDaWR5BXV1aWQyKwZub2RlXzMAAAAAAAAAACoBYwADaWR4BXV1aWQxAgZub2RlXzEAAAAAAAAAAAEBYQADaWR5BXV1aWQyKgZub2RlXzIAAAAAAAAAAAwBYgACBXV1aWQyAAAFdXVpZDEAAQltYXRjaF9hbGw_gAAAAA", + "keep_alive": "1m" + } + }), + ); + } +} diff --git a/src/search/request.rs b/src/search/request.rs index 28345f4..8d92776 100644 --- a/src/search/request.rs +++ b/src/search/request.rs @@ -63,6 +63,9 @@ pub struct Search { #[serde(skip_serializing_if = "ShouldSkip::should_skip")] post_filter: Option, + #[serde(skip_serializing_if = "ShouldSkip::should_skip")] + pit: Option, + #[serde(skip_serializing_if = "ShouldSkip::should_skip")] search_after: Terms, } @@ -241,6 +244,12 @@ impl Search { self } + /// Point in time + pub fn pit(mut self, pit: PointInTime) -> Self { + self.pit = Some(pit); + self + } + /// Search after a set of sort values. pub fn search_after(mut self, sort_values: T) -> Self where