elastic_query_builder/mapping/
properties.rs

1use crate::mapping::MappingTrait;
2use crate::util::UtilMap;
3use serde_json::Value;
4use std::collections::HashMap;
5
6#[derive(Default)]
7pub struct MappingProperties {
8    properties: HashMap<String, Box<dyn MappingTrait>>,
9}
10
11impl MappingProperties {
12    pub fn new() -> Self
13    where
14        Self: Sized,
15    {
16        MappingProperties::default()
17    }
18    pub fn add_property<T>(&mut self, key: &str, value: T) -> &mut MappingProperties
19    where
20        T: MappingTrait + 'static,
21    {
22        self.properties.insert(key.to_string(), Box::new(value));
23        self
24    }
25}
26
27impl MappingTrait for MappingProperties {
28    fn build(&self) -> Value {
29        let mut map = UtilMap::new();
30        for (k, v) in &self.properties {
31            map.append_value(k, v.build());
32        }
33        map.build_object("properties")
34    }
35
36    fn query_name(&self) -> String {
37        "properties".to_string()
38    }
39}