aliyun_log_rust_sdk/client/
index.rs

1use serde::{Deserialize, Serialize};
2
3mod create_index;
4pub use create_index::*;
5
6mod update_index;
7pub use update_index::*;
8
9mod get_index;
10pub use get_index::*;
11
12mod delete_index;
13pub use delete_index::*;
14
15use super::*;
16
17/// Builder for constructing Index configuration.
18///
19/// Provides a fluent API for building complex index configurations with full-text search,
20/// field indexing, and log clustering capabilities.
21///
22/// # Examples
23///
24/// ```no_run
25/// use aliyun_log_rust_sdk::{Index, FullTextIndex, FieldIndex, IndexKeyText, token_list};
26/// use std::collections::HashMap;
27///
28/// // Configure with full-text index
29/// let full_text_index = FullTextIndex {
30///     case_sensitive: false,
31///     chn: true,
32///     token: token_list![",", " ", ";"],
33/// };
34///
35/// let index = Index::builder()
36///     .line(full_text_index)
37///     .build();
38///
39/// // Configure with field indexes
40/// let mut keys = HashMap::new();
41/// keys.insert(
42///     "level".to_string(),
43///     FieldIndex::Text(IndexKeyText {
44///         case_sensitive: false,
45///         alias: None,
46///         chn: false,
47///         token: token_list![],
48///         doc_value: true,
49///     })
50/// );
51///
52/// let index = Index::builder()
53///     .keys(keys)
54///     .build();
55/// ```
56#[derive(Default)]
57pub struct IndexBuilder {
58    max_text_len: Option<i32>,
59    line: Option<FullTextIndex>,
60    keys: Option<std::collections::HashMap<String, FieldIndex>>,
61    scan_index: Option<bool>,
62    log_reduce: Option<bool>,
63    log_reduce_white_list: Option<Vec<String>>,
64    log_reduce_black_list: Option<Vec<String>>,
65}
66
67impl IndexBuilder {
68    pub fn new() -> Self {
69        Self {
70            max_text_len: None,
71            line: None,
72            keys: None,
73            scan_index: None,
74            log_reduce: None,
75            log_reduce_white_list: None,
76            log_reduce_black_list: None,
77        }
78    }
79
80    /// Set the maximum length for statistics fields.
81    ///
82    /// # Arguments
83    ///
84    /// * `max_text_len` - Maximum text length for indexed fields’ doc value
85    pub fn max_text_len(mut self, max_text_len: i32) -> Self {
86        self.max_text_len = Some(max_text_len);
87        self
88    }
89
90    /// Set full-text index configuration.
91    ///
92    /// # Arguments
93    ///
94    /// * `line` - Full-text index configuration
95    pub fn line(mut self, line: FullTextIndex) -> Self {
96        self.line = Some(line);
97        self
98    }
99
100    /// Set field index configuration.
101    ///
102    /// # Arguments
103    ///
104    /// * `keys` - Field index configuration map
105    pub fn keys(mut self, keys: std::collections::HashMap<String, FieldIndex>) -> Self {
106        self.keys = Some(keys);
107        self
108    }
109
110    /// Enable or disable scan index.
111    ///
112    /// # Arguments
113    ///
114    /// * `scan_index` - Whether to enable scan index
115    pub fn scan_index(mut self, scan_index: bool) -> Self {
116        self.scan_index = Some(scan_index);
117        self
118    }
119
120    /// Enable or disable log clustering.
121    ///
122    /// # Arguments
123    ///
124    /// * `log_reduce` - Whether to enable log clustering
125    pub fn log_reduce(mut self, log_reduce: bool) -> Self {
126        self.log_reduce = Some(log_reduce);
127        self
128    }
129
130    /// Set whitelist for log clustering fields.
131    ///
132    /// Only effective when log clustering is enabled.
133    ///
134    /// # Arguments
135    ///
136    /// * `log_reduce_white_list` - List of field names to include in clustering
137    pub fn log_reduce_white_list(mut self, log_reduce_white_list: Vec<String>) -> Self {
138        self.log_reduce_white_list = Some(log_reduce_white_list);
139        self
140    }
141
142    /// Set blacklist for log clustering fields.
143    ///
144    /// Only effective when log clustering is enabled.
145    ///
146    /// # Arguments
147    ///
148    /// * `log_reduce_black_list` - List of field names to exclude from clustering
149    pub fn log_reduce_black_list(mut self, log_reduce_black_list: Vec<String>) -> Self {
150        self.log_reduce_black_list = Some(log_reduce_black_list);
151        self
152    }
153
154    /// Build the Index configuration.
155    pub fn build(self) -> Index {
156        Index {
157            max_text_len: self.max_text_len,
158            line: self.line,
159            keys: self.keys,
160            scan_index: self.scan_index,
161            log_reduce: self.log_reduce,
162            log_reduce_white_list: self.log_reduce_white_list,
163            log_reduce_black_list: self.log_reduce_black_list,
164        }
165    }
166}
167
168/// Index configuration for a logstore.
169///
170/// Defines how logs are indexed for querying and analysis, including full-text search,
171/// field indexing, and log clustering capabilities.
172///
173/// # Examples
174///
175/// ```no_run
176/// use aliyun_log_rust_sdk::{Index, FullTextIndex, FieldIndex, IndexKeyText, token_list};
177/// use std::collections::HashMap;
178///
179/// // Configure with full-text index
180/// let full_text_index = FullTextIndex {
181///     case_sensitive: false,
182///     chn: true,
183///     token: token_list![",", " ", ";"],
184/// };
185///
186/// let index = Index::builder()
187///     .line(full_text_index)
188///     .build();
189///
190/// // Configure with field indexes
191/// let mut keys = HashMap::new();
192/// keys.insert(
193///     "level".to_string(),
194///     FieldIndex::Text(IndexKeyText {
195///         case_sensitive: false,
196///         alias: None,
197///         chn: false,
198///         token: token_list![],
199///         doc_value: true,
200///     })
201/// );
202///
203/// let index = Index::builder()
204///     .keys(keys)
205///     .build();
206/// ```
207#[derive(Serialize, Deserialize, Default)]
208pub struct Index {
209    /// Maximum length for statistics fields
210    #[serde(skip_serializing_if = "Option::is_none")]
211    pub max_text_len: Option<i32>,
212    /// Full-text index configuration
213    #[serde(skip_serializing_if = "Option::is_none")]
214    pub line: Option<FullTextIndex>,
215    /// Field index configuration map
216    #[serde(skip_serializing_if = "Option::is_none")]
217    pub keys: Option<std::collections::HashMap<String, FieldIndex>>,
218    /// Whether to enable scan index
219    #[serde(skip_serializing_if = "Option::is_none")]
220    pub scan_index: Option<bool>,
221    /// Whether to enable log clustering
222    #[serde(skip_serializing_if = "Option::is_none")]
223    pub log_reduce: Option<bool>,
224    /// Whitelist for log clustering fields (only effective when log_reduce is enabled)
225    #[serde(skip_serializing_if = "Option::is_none")]
226    pub log_reduce_white_list: Option<Vec<String>>,
227    /// Blacklist for log clustering fields (only effective when log_reduce is enabled)
228    #[serde(skip_serializing_if = "Option::is_none")]
229    pub log_reduce_black_list: Option<Vec<String>>,
230}
231
232impl Index {
233    /// Create a new empty Index configuration.
234    pub fn new() -> Self {
235        Self::default()
236    }
237
238    /// Create a new IndexBuilder for fluent configuration.
239    pub fn builder() -> IndexBuilder {
240        IndexBuilder::new()
241    }
242}
243
244/// Full-text index configuration.
245///
246/// Configures how full-text search is performed on log content.
247///
248/// # Examples
249///
250/// ```
251/// use aliyun_log_rust_sdk::{FullTextIndex, token_list};
252///
253/// let full_text_index = FullTextIndex {
254///     case_sensitive: false,
255///     chn: true,
256///     token: token_list![",", " ", ";", "\n", "\t"],
257/// };
258/// ```
259#[derive(Serialize, Deserialize)]
260pub struct FullTextIndex {
261    /// Whether the search is case-sensitive
262    #[serde(rename = "caseSensitive")]
263    pub case_sensitive: bool,
264    /// Whether to enable Chinese word segmentation
265    pub chn: bool,
266    /// List of delimiter tokens for tokenization
267    pub token: Vec<String>,
268}
269
270/// Field index type enumeration.
271///
272/// Defines different types of field indexes that can be applied to log fields.
273///
274/// # Variants
275///
276/// * `Text` - Text field index for string content
277/// * `Long` - Long integer field index for numeric values
278/// * `Double` - Double precision float field index for decimal numbers
279/// * `Json` - JSON field index for nested JSON content
280///
281/// # Examples
282///
283/// ```
284/// use aliyun_log_rust_sdk::{FieldIndex, IndexKeyText, token_list};
285///
286/// let field_index = FieldIndex::Text(IndexKeyText {
287///     case_sensitive: false,
288///     alias: None,
289///     chn: false,
290///     token: token_list![",", "\t", " "],
291///     doc_value: true,
292/// });
293/// ```
294#[derive(Serialize, Deserialize)]
295#[serde(tag = "type", rename_all = "snake_case")]
296pub enum FieldIndex {
297    Text(IndexKeyText),
298    Long(IndexKeyLong),
299    Double(IndexKeyDouble),
300    Json(IndexKeyJson),
301}
302
303/// JSON field index configuration.
304///
305/// Configures indexing for JSON-type fields with nested structure support.
306///
307/// # Examples
308///
309/// ```
310/// use aliyun_log_rust_sdk::{IndexKeyJson, token_list};
311/// use std::collections::HashMap;
312///
313/// let json_index = IndexKeyJson {
314///     case_sensitive: false,
315///     alias: None,
316///     chn: false,
317///     token: token_list![",", "\t", " "],
318///     doc_value: true,
319///     max_depth: 3,
320///     index_all: true,
321///     json_keys: None,
322/// };
323/// ```
324#[derive(Serialize, Deserialize)]
325pub struct IndexKeyJson {
326    /// Whether the search is case-sensitive
327    #[serde(rename = "caseSensitive")]
328    pub case_sensitive: bool,
329    /// Field alias for display
330    #[serde(skip_serializing_if = "Option::is_none")]
331    pub alias: Option<String>,
332    /// Whether to enable Chinese word segmentation
333    pub chn: bool,
334    /// List of delimiter tokens for tokenization
335    pub token: Vec<String>,
336    /// Whether to enable doc value for analytics
337    pub doc_value: bool,
338    /// Maximum depth for JSON structure indexing, -1 means no limit
339    pub max_depth: i32,
340    /// Whether to index all fields in the JSON structure
341    pub index_all: bool,
342    /// Specific JSON keys to index
343    #[serde(skip_serializing_if = "Option::is_none")]
344    pub json_keys: Option<std::collections::HashMap<String, IndexJsonKey>>,
345}
346
347/// JSON nested field index type enumeration.
348///
349/// Defines the types of indexes that can be applied to nested fields within JSON.
350///
351/// # Examples
352///
353/// ```
354/// use aliyun_log_rust_sdk::{IndexJsonKey, IndexKeyText, token_list};
355///
356/// let json_field = IndexJsonKey::Text(IndexKeyText {
357///     case_sensitive: false,
358///     alias: None,
359///     chn: false,
360///     token: token_list![",", "\t", " "],
361///     doc_value: true,
362/// });
363/// ```
364#[derive(Serialize, Deserialize)]
365#[serde(tag = "type", rename_all = "snake_case")]
366pub enum IndexJsonKey {
367    Text(IndexKeyText),
368    Long(IndexKeyLong),
369    Double(IndexKeyDouble),
370}
371
372/// Text field index configuration.
373///
374/// Configures indexing for text-type fields with full-text search capabilities.
375#[derive(Serialize, Deserialize)]
376pub struct IndexKeyText {
377    /// Whether the search is case-sensitive
378    #[serde(rename = "caseSensitive")]
379    pub case_sensitive: bool,
380    /// Field alias for display
381    #[serde(skip_serializing_if = "Option::is_none")]
382    pub alias: Option<String>,
383    /// Whether to enable Chinese word segmentation
384    pub chn: bool,
385    /// List of delimiter tokens for tokenization
386    pub token: Vec<String>,
387    /// Whether to enable doc value for analytics
388    pub doc_value: bool,
389}
390
391/// Long integer field index configuration.
392///
393/// Configures indexing for long integer fields.
394#[derive(Serialize, Deserialize)]
395pub struct IndexKeyLong {
396    /// Field alias for display
397    #[serde(skip_serializing_if = "Option::is_none")]
398    pub alias: Option<String>,
399    /// Whether to enable doc value for analytics
400    pub doc_value: bool,
401}
402
403/// Double precision float field index configuration.
404///
405/// Configures indexing for double precision floating-point fields.
406#[derive(Serialize, Deserialize)]
407pub struct IndexKeyDouble {
408    /// Field alias for display
409    #[serde(skip_serializing_if = "Option::is_none")]
410    pub alias: Option<String>,
411    /// Whether to enable doc value for analytics
412    pub doc_value: bool,
413}
414
415/// Text field index configuration.
416///
417/// Configures indexing for text-type fields with full-text search capabilities.
418#[derive(Serialize, Deserialize)]
419pub struct IndexKeyJsonText {
420    /// Field alias for display
421    #[serde(skip_serializing_if = "Option::is_none")]
422    pub alias: Option<String>,
423    /// Whether to enable doc value for analytics
424    pub doc_value: bool,
425}