elasticsearch_dsl/search/queries/joining/
parent_id_query.rs1use crate::search::*;
2use crate::util::*;
3
4#[derive(Debug, Clone, PartialEq, Serialize)]
16#[serde(remote = "Self")]
17pub struct ParentIdQuery {
18 r#type: String,
19
20 id: String,
21
22 #[serde(skip_serializing_if = "ShouldSkip::should_skip")]
23 ignore_unmapped: Option<bool>,
24
25 #[serde(skip_serializing_if = "ShouldSkip::should_skip")]
26 boost: Option<f32>,
27
28 #[serde(skip_serializing_if = "ShouldSkip::should_skip")]
29 _name: Option<String>,
30}
31
32impl Query {
33 pub fn parent_id<T, U>(r#type: T, id: U) -> ParentIdQuery
39 where
40 T: ToString,
41 U: ToString,
42 {
43 ParentIdQuery {
44 r#type: r#type.to_string(),
45 id: id.to_string(),
46 ignore_unmapped: None,
47 boost: None,
48 _name: None,
49 }
50 }
51}
52
53impl ParentIdQuery {
54 pub fn ignore_unmapped(mut self, ignore_unmapped: bool) -> Self {
61 self.ignore_unmapped = Some(ignore_unmapped);
62 self
63 }
64
65 add_boost_and_name!();
66}
67
68impl ShouldSkip for ParentIdQuery {
69 fn should_skip(&self) -> bool {
70 self.r#type.should_skip() || self.id.should_skip()
71 }
72}
73
74serialize_with_root!("parent_id": ParentIdQuery);
75
76#[cfg(test)]
77mod tests {
78 use super::*;
79
80 #[test]
81 fn serialization() {
82 assert_serialize_query(
83 Query::parent_id("my-child", 1),
84 json!({
85 "parent_id": {
86 "type": "my-child",
87 "id": "1"
88 }
89 }),
90 );
91
92 assert_serialize_query(
93 Query::parent_id("my-child", 1)
94 .boost(2)
95 .name("test")
96 .ignore_unmapped(true),
97 json!({
98 "parent_id": {
99 "type": "my-child",
100 "id": "1",
101 "ignore_unmapped": true,
102 "boost": 2.0,
103 "_name": "test"
104 }
105 }),
106 );
107 }
108}