Skip to content

Commit

Permalink
ilm
Browse files Browse the repository at this point in the history
  • Loading branch information
uiuifree committed Jul 28, 2024
1 parent e8ad979 commit 176b307
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/mapping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::mapping::field_type::keyword::KeywordFieldType;
use crate::mapping::field_type::text::TextFieldType;
use crate::mapping::properties::MappingProperties;
use crate::util::UtilMap;
use serde_json::Value;
use serde_json::{json, Value};

pub trait MappingTrait {
fn build(&self) -> Value;
Expand All @@ -14,12 +14,14 @@ pub trait MappingTrait {

pub struct MappingBuilder {
properties: MappingProperties,
setting: Option<Value>,
}

impl MappingBuilder {
pub fn new() -> MappingBuilder {
MappingBuilder {
properties: MappingProperties::new(),
setting: None,
}
}
pub fn add_property<T>(&mut self, key: &str, value: T) -> &mut MappingBuilder
Expand All @@ -32,9 +34,15 @@ impl MappingBuilder {
pub fn set_properties(&mut self, properties: MappingProperties) {
self.properties = properties;
}
pub fn set_setting(&mut self, properties: Value) {
self.setting = Some(properties);
}
pub fn build(self) -> Value {
let mut map = UtilMap::new();
map.append_value("mappings", self.properties.build());
if let Some(ref setting) = self.setting {
map.append_value("setting", setting.clone())
}
map.build()
}
}
Expand All @@ -45,5 +53,8 @@ fn test() {
mapping
.add_property("title", KeywordFieldType::new())
.add_property("content", TextFieldType::new());
mapping.set_setting(json!({
"index.lifecycle.name": "logs_policy"
}));
println!("{}", mapping.build().to_string())
}

0 comments on commit 176b307

Please sign in to comment.