extern crate elastic;
extern crate env_logger;
use std::error::Error;
use elastic::prelude::*;
fn run() -> Result<(), Box<Error>> {
let client = SyncClientBuilder::new().build()?;
let bulk = client
.request(BulkRequest::new(bulk_body()))
.send()?
.into_response::<BulkResponse>()?;
for op in bulk {
match op {
Ok(op) => println!("ok: {:?}", op),
Err(op) => println!("err: {:?}", op),
}
}
Ok(())
}
fn bulk_body() -> String {
let mut bulk = String::new();
for i in 1..1000 {
let header = format!(
"{{ \"index\" : {{ \"_index\" : \"test\", \"_type\" : \"ty\", \"_id\" : \"{}\" }} }}",
i
);
let body = format!("{{ \"title\" : \"string value {}\" }}", i);
bulk.push_str(&header);
bulk.push('\n');
bulk.push_str(&body);
bulk.push('\n');
}
bulk
}
fn main() {
env_logger::init().unwrap();
run().unwrap()
}