elastic_responses/
update.rs

1/*!
2Response types for a [update document request](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html).
3*/
4
5use parsing::{HttpResponseHead, IsOk, MaybeOkResponse, ResponseBody, Unbuffered};
6use common::DocumentResult;
7use error::*;
8
9/** Response for a [update document request](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html). */
10#[derive(Deserialize, Debug)]
11pub struct UpdateResponse {
12    #[serde(rename = "_index")] index: String,
13    #[serde(rename = "_type")] ty: String,
14    #[serde(rename = "_id")] id: String,
15    #[serde(rename = "_version")] version: Option<u32>,
16    #[serde(rename = "_routing")] routing: Option<String>,
17    result: DocumentResult,
18}
19
20impl UpdateResponse {
21    /** Whether or not the document was updated. */
22    pub fn updated(&self) -> bool {
23        match self.result {
24            DocumentResult::Updated => true,
25            _ => false,
26        }
27    }
28
29    /** The index for the document. */
30    pub fn index(&self) -> &str {
31        &self.index
32    }
33
34    /** The type of the document. */
35    pub fn ty(&self) -> &str {
36        &self.ty
37    }
38
39    /** The id of the document. */
40    pub fn id(&self) -> &str {
41        &self.id
42    }
43
44    /** The version of the document. */
45    pub fn version(&self) -> Option<u32> {
46        self.version.clone()
47    }
48}
49
50impl IsOk for UpdateResponse {
51    fn is_ok<B: ResponseBody>(head: HttpResponseHead, body: Unbuffered<B>) -> Result<MaybeOkResponse<B>, ParseResponseError> {
52        match head.status() {
53            200...299 => Ok(MaybeOkResponse::ok(body)),
54            _ => Ok(MaybeOkResponse::err(body)),
55        }
56    }
57}