use reqwest::StatusCode;
use serde::Deserialize;
use crate::{error::EsError, Client, EsResponse};
use super::{format_multi, ShardCountResult};
#[derive(Debug)]
pub struct RefreshOperation<'a, 'b> {
client: &'a mut Client,
indexes: &'b [&'b str],
}
impl<'a, 'b> RefreshOperation<'a, 'b> {
pub fn new(client: &'a mut Client) -> RefreshOperation {
RefreshOperation {
client,
indexes: &[],
}
}
pub fn with_indexes(&'b mut self, indexes: &'b [&'b str]) -> &'b mut Self {
self.indexes = indexes;
self
}
pub fn send(&mut self) -> Result<RefreshResult, EsError> {
let url = format!("/{}/_refresh", format_multi(&self.indexes));
let response = self.client.post_op(&url)?;
match response.status_code() {
StatusCode::OK => Ok(response.read_response()?),
status_code => Err(EsError::EsError(format!(
"Unexpected status: {}",
status_code
))),
}
}
}
impl Client {
pub fn refresh(&mut self) -> RefreshOperation {
RefreshOperation::new(self)
}
}
#[derive(Deserialize)]
pub struct RefreshResult {
#[serde(rename = "_shards")]
pub shards: ShardCountResult,
}