use serde::Serialize;
use crate::{util::*, Query, SpanQuery};
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(remote = "Self")]
pub struct SpanFirstQuery {
r#match: Box<SpanQuery>,
end: u32,
}
impl Query {
pub fn span_first<T>(r#match: T, end: u32) -> SpanFirstQuery
where
T: Into<SpanQuery>,
{
SpanFirstQuery {
r#match: Box::new(r#match.into()),
end,
}
}
}
impl ShouldSkip for SpanFirstQuery {}
serialize_with_root!("span_first": SpanFirstQuery);
deserialize_with_root!("span_first": SpanFirstQuery);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn serialization() {
assert_serialize_query(
Query::span_first(Query::span_term("test", 1234), 10),
json!({
"span_first": {
"match": {
"span_term": {
"test": {
"value": 1234
}
}
},
"end": 10
}
}),
);
assert_serialize_query(
Query::span_first(Query::span_term("test", 1234), 10),
json!({
"span_first": {
"match": {
"span_term": {
"test": {
"value": 1234
}
}
},
"end": 10
}
}),
);
}
}