#[macro_use]
extern crate elastic_derive;
extern crate env_logger;
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_json;
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(),
};
let doc_id = doc.id;
client.index_create(sample_index()).send()?;
client
.document_put_mapping::<MyType>(sample_index())
.send()?;
client
.document_index(sample_index(), id(doc_id), doc)
.params(|p| p.url_param("refresh", true))
.send()?;
let update = client
.document_update::<MyType>(sample_index(), id(doc_id))
.script(r#"ctx._source.title = "A new title""#)
.send()?;
assert!(update.updated());
Ok(())
}
fn main() {
env_logger::init().unwrap();
run().unwrap();
}
fn sample_index() -> Index<'static> {
Index::from("index_sample_index")
}