extern crate elastic;
extern crate env_logger;
extern crate serde_json;
use std::error::Error as StdError;
use serde_json::Value;
use elastic::error::{ApiError, Error};
use elastic::prelude::*;
fn run() -> Result<(), Box<StdError>> {
let client = SyncClientBuilder::new().build()?;
let res = client
.document_get::<Value>(index("typed_sample_index"), id("1"))
.ty("mytype")
.send();
match res.map(|res| res.into_document()) {
Ok(Some(doc)) => {
println!("document found: {:?}", doc);
}
Ok(None) => {
println!("document not found, but index exists");
}
Err(Error::Api(ApiError::IndexNotFound { .. })) => {
println!("index not found");
}
Err(e) => Err(e)?,
}
Ok(())
}
fn main() {
env_logger::init().unwrap();
run().unwrap()
}