#[macro_use]
extern crate elastic_derive;
extern crate env_logger;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate elastic;
use std::error::Error;
use elastic::prelude::*;
#[derive(Debug, Serialize, Deserialize, ElasticType)]
struct MyType {
id: i32,
title: String,
timestamp: Date<DefaultDateMapping>,
}
fn run() -> Result<(), Box<Error>> {
let client = SyncClientBuilder::new().build()?;
let doc = MyType {
id: 1,
title: String::from("A title"),
timestamp: Date::now(),
};
if !client.index_exists(sample_index()).send()?.exists() {
client.index_create(sample_index()).send()?;
}
client
.document_put_mapping::<MyType>(sample_index())
.send()?;
client
.document_index(sample_index(), id(doc.id), doc)
.send()?;
Ok(())
}
fn main() {
env_logger::init().unwrap();
run().unwrap();
}
fn sample_index() -> Index<'static> {
Index::from("index_sample_index")
}