elastic_query_builder/mapping/field_type/
keyword.rs

1use crate::mapping::MappingTrait;
2use crate::util::UtilMap;
3use serde_json::Value;
4
5///  https://www.elastic.co/guide/en/elasticsearch/reference/current/binary.html
6#[derive(Default)]
7pub struct KeywordFieldType {
8    index: Option<bool>,
9}
10
11impl KeywordFieldType {
12    pub fn new() -> Self {
13        KeywordFieldType::default()
14    }
15    pub fn set_index(&mut self, index: bool) {
16        self.index = Some(index);
17    }
18}
19
20impl MappingTrait for KeywordFieldType {
21    fn build(&self) -> Value {
22        let mut map = UtilMap::new();
23        map.append_string("type", self.query_name());
24        if self.index.is_some() {
25            map.append_string("index", self.index.clone().unwrap().to_string());
26        }
27        map.build()
28    }
29
30    fn query_name(&self) -> String {
31        "keyword".to_string()
32    }
33}
34
35#[test]
36fn test() {
37    let query = KeywordFieldType::new().build();
38    println!("{:?}", query)
39}