elasticsearch_dsl/search/aggregations/params/
terms_exclude.rs

1use crate::util::ShouldSkip;
2
3/// Filter the values for which buckets will be created.
4#[derive(Debug, Clone, Serialize, PartialEq)]
5#[serde(untagged)]
6pub enum TermsExclude {
7    /// Filter buckets by their regular expression pattern.
8    ///
9    /// <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_filtering_values_with_regular_expressions_2>
10    Regex(String),
11
12    /// Filter buckets by their exact value.
13    ///
14    /// <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_filtering_values_with_exact_values_2>
15    Exact(Vec<String>),
16}
17
18impl ShouldSkip for TermsExclude {
19    fn should_skip(&self) -> bool {
20        match self {
21            Self::Regex(ref s) => s.is_empty(),
22            Self::Exact(ref v) => v.is_empty(),
23        }
24    }
25}
26
27impl From<String> for TermsExclude {
28    fn from(s: String) -> Self {
29        Self::Regex(s)
30    }
31}
32
33impl From<&str> for TermsExclude {
34    fn from(s: &str) -> Self {
35        Self::Regex(s.to_string())
36    }
37}
38
39impl From<Vec<String>> for TermsExclude {
40    fn from(v: Vec<String>) -> Self {
41        Self::Exact(v)
42    }
43}
44
45impl From<Vec<&str>> for TermsExclude {
46    fn from(v: Vec<&str>) -> Self {
47        Self::Exact(v.iter().map(|s| s.to_string()).collect())
48    }
49}
50
51impl From<&[&str]> for TermsExclude {
52    fn from(v: &[&str]) -> Self {
53        Self::Exact(v.iter().map(|s| s.to_string()).collect())
54    }
55}
56
57impl<const N: usize> From<[&str; N]> for TermsExclude {
58    fn from(value: [&str; N]) -> Self {
59        Self::Exact(value.iter().map(|s| s.to_string()).collect())
60    }
61}