os_query_builder_rs/
lib.rs1pub mod full_text;
2pub mod misc;
3pub mod term;
4pub mod compound_query;
5
6pub mod model {
7 use serde::Serialize;
8 use serde_json::Value;
9 use crate::misc::query_field::QueryField;
10
11
12 #[derive(Debug, Default, Clone, Serialize)]
33 pub struct Query {
34 #[serde(skip_serializing_if = "Option::is_none")]
35 from: Option<usize>,
36
37 #[serde(skip_serializing_if = "Option::is_none")]
38 size: Option<usize>,
39
40 #[serde(rename = "_source", skip_serializing_if = "Option::is_none")]
41 source: Option<Vec<String>>,
42
43 #[serde(skip_serializing_if = "Option::is_none")]
44 query: Option<QueryField>,
45
46 #[serde(skip_serializing_if = "Option::is_none")]
47 aggs: Option<Value>,
48 }
49
50 impl Query {
51 pub fn new() -> Self {
52 Self::default()
53 }
54
55 pub fn source<F, T>(self, source: F) -> Self
56 where
57 F: IntoIterator<Item=T>,
58 T: Into<String>
59 {
60 Self {
61 source: Some(source
62 .into_iter()
63 .map(|x| x.into())
64 .collect()),
65 ..self
66 }
67 }
68
69 pub fn query<T: Into<QueryField> + Serialize>(self, query: T) -> Self {
70 Self {
71 query: Some(query.into()),
72 ..self
73 }
74 }
75
76 pub fn from<T: Into<usize> + Serialize>(self, from: T) -> Self {
77 Self {
78 from: Some(from.into()),
79 ..self
80 }
81 }
82
83 pub fn size<T: Into<usize> + Serialize>(self, size: T) -> Self {
84 Self {
85 size: Some(size.into()),
86 ..self
87 }
88 }
89
90 pub fn aggs<T: Into<Value> + Serialize>(self, aggs: T) -> Self {
91 Self {
92 aggs: Some(aggs.into()),
93 ..self
94 }
95 }
96 }
97}