rs_es/operations/mod.rs
1/*
2 * Copyright 2015-2018 Ben Ashford
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//! Implementations of specific ElasticSearch operations
18//!
19//! The various methods on [`Client`](../struct.Client.html) are entry points to
20//! ElasticSearch's set of operations. This module, and it's child modules are
21//! the implementation of those operations.
22
23use std::borrow::Cow;
24
25use serde::{Serialize, Deserialize};
26
27use crate::util::StrJoin;
28
29// Specific operations
30#[macro_use]
31pub mod common;
32
33pub mod analyze;
34pub mod bulk;
35pub mod delete;
36pub mod delete_index;
37pub mod get;
38pub mod index;
39pub mod mapping;
40pub mod refresh;
41pub mod search;
42pub mod version;
43
44// Common utility functions
45
46/// A repeating convention in the ElasticSearch REST API is parameters that can
47/// take multiple values
48fn format_multi<'a>(parts: &[&'a str]) -> Cow<'a, str> {
49 match parts.len() {
50 0 => Cow::Borrowed("_all"),
51 1 => Cow::Borrowed(parts[0]),
52 _ => Cow::Owned(parts.iter().join(",")),
53 }
54}
55
56/// Multiple operations require indexes and types to be specified, there are
57/// rules for combining the two however. E.g. all indexes is specified with
58/// `_all`, but all types are specified by omitting type entirely.
59fn format_indexes_and_types<'a>(indexes: &[&'a str], types: &[&str]) -> Cow<'a, str> {
60 if types.is_empty() {
61 format_multi(indexes)
62 } else {
63 Cow::Owned(format!("{}/{}", format_multi(indexes), format_multi(types)))
64 }
65}
66
67// Results
68
69/// Shared struct for operations that include counts of success/failed shards.
70/// This is returned within various other result structs.
71#[derive(Debug, Deserialize, Serialize)]
72pub struct ShardCountResult {
73 pub total: u64,
74 pub successful: u64,
75 pub failed: u64,
76}
77
78#[derive(Debug, Deserialize)]
79pub struct GenericResult {
80 pub acknowledged: bool,
81}