use crate::{search::*, util::*};
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(remote = "Self")]
pub struct ExistsQuery {
field: String,
#[serde(default, skip_serializing_if = "ShouldSkip::should_skip")]
boost: Option<f32>,
#[serde(default, skip_serializing_if = "ShouldSkip::should_skip")]
_name: Option<String>,
}
impl Query {
pub fn exists<T>(field: T) -> ExistsQuery
where
T: ToString,
{
ExistsQuery {
field: field.to_string(),
boost: None,
_name: None,
}
}
}
impl ExistsQuery {
add_boost_and_name!();
}
impl ShouldSkip for ExistsQuery {}
serialize_with_root!("exists": ExistsQuery);
deserialize_with_root!("exists": ExistsQuery);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn serialization() {
assert_serialize_query(
Query::exists("test"),
json!({
"exists": {
"field": "test"
}
}),
);
assert_serialize_query(
Query::exists("test").boost(2).name("test"),
json!({
"exists": {
"field": "test",
"boost": 2.0,
"_name": "test"
}
}),
);
}
}