elasticsearch_dsl/search/response/
shard_statistics.rs1use super::ShardFailure;
2use crate::util::ShouldSkip;
3
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
6pub struct ShardStatistics {
7 pub total: u32,
9
10 pub successful: u32,
12
13 pub skipped: u32,
15
16 pub failed: u32,
18
19 #[serde(skip_serializing_if = "ShouldSkip::should_skip", default)]
21 pub failures: Vec<ShardFailure>,
22}
23
24impl Default for ShardStatistics {
25 fn default() -> Self {
26 Self {
27 total: 1,
28 successful: 1,
29 skipped: 0,
30 failed: 0,
31 failures: Vec::new(),
32 }
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn deserializes_successfully() {
42 let value = json!({
43 "total": 280,
44 "successful": 277,
45 "skipped": 0,
46 "failed": 3,
47 "failures": [
48 {
49 "shard": 1,
50 "index": "nbs_comprehend-2021-w41",
51 "node": "oGEHA-aRSnmwuEmqSZc6Kw",
52 "reason": {
53 "type": "script_exception",
54 "reason": "runtime error",
55 "script_stack": [
56 "org.elasticsearch.index.fielddata.ScriptDocValues$Longs.get(ScriptDocValues.java:121)",
57 "org.elasticsearch.index.fielddata.ScriptDocValues$Longs.getValue(ScriptDocValues.java:115)",
58 "doc['user.followers_count'].value > 9999 ? 1 : 0",
59 " ^---- HERE"
60 ],
61 "script": "doc['user.followers_count'].value > 9999 ? 1 : 0",
62 "lang": "painless",
63 "position": {
64 "offset": 27,
65 "start": 0,
66 "end": 48
67 },
68 "caused_by": {
69 "type": "illegal_state_exception",
70 "reason": "A document doesn't have a value for a field! Use doc[<field>].size()==0 to check if a document is missing a field!"
71 }
72 }
73 }
74 ]
75 });
76
77 let _ = serde_json::from_value::<ShardStatistics>(value).unwrap();
78 }
79}