Browse Source

Just use _source instead of _source + fields

main
Dylan Baker 3 years ago
parent
commit
b29cf12916
1 changed files with 4 additions and 11 deletions
  1. 4
    11
      src/compiler.rs

+ 4
- 11
src/compiler.rs View File

@@ -29,23 +29,18 @@ impl Display for Query {
29 29
 }
30 30
 
31 31
 pub fn compile(expr: Select) -> Result<Query, CompilerError> {
32
-    let mut source = false;
33 32
     let field_names: Vec<Value> = expr
34 33
         .fields
35 34
         .iter()
36 35
         .map(|f| match f {
37
-            Field::Star => {
38
-                source = true;
39
-                Value::String("*".to_string())
40
-            }
36
+            Field::Star => Value::String("*".to_string()),
41 37
             Field::Named(name) => Value::String(name.clone()),
42 38
         })
43 39
         .collect();
44 40
 
45 41
     let body = json!({
46 42
         "query": { "match_all":{} },
47
-        "_source": source,
48
-        "fields": Value::Array(field_names)
43
+        "_source": Value::Array(field_names)
49 44
     });
50 45
 
51 46
     Ok(Query::new(expr.source, body))
@@ -73,8 +68,7 @@ mod tests {
73 68
                     "query": {
74 69
                         "match_all": {}
75 70
                     },
76
-                    "fields": ["*"],
77
-                    "_source": true
71
+                    "_source": ["*"]
78 72
                 })
79 73
             )
80 74
         )
@@ -90,8 +84,7 @@ mod tests {
90 84
                     "query": {
91 85
                         "match_all": {}
92 86
                     },
93
-                    "fields": ["foo"],
94
-                    "_source": false
87
+                    "_source": ["foo"]
95 88
                 })
96 89
             )
97 90
         )

Loading…
Cancel
Save