Skip to content

Commit

Permalink
Add support for PIT parameters (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
buinauskas authored Sep 8, 2023
1 parent dd61f96 commit 2d002b5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/search/params/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::*;
Expand Down
43 changes: 43 additions & 0 deletions src/search/params/point_in_time.rs
Original file line number Diff line number Diff line change
@@ -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<T>(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"
}
}),
);
}
}
9 changes: 9 additions & 0 deletions src/search/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ pub struct Search {
#[serde(skip_serializing_if = "ShouldSkip::should_skip")]
post_filter: Option<Query>,

#[serde(skip_serializing_if = "ShouldSkip::should_skip")]
pit: Option<PointInTime>,

#[serde(skip_serializing_if = "ShouldSkip::should_skip")]
search_after: Terms,
}
Expand Down Expand Up @@ -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<T>(mut self, sort_values: T) -> Self
where
Expand Down

0 comments on commit 2d002b5

Please sign in to comment.