summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-08-24 14:13:56 -0700
committerBryan Newbold <bnewbold@archive.org>2020-08-24 14:13:56 -0700
commit780ca2a819a6d1c931580c8e8e31657072971876 (patch)
treec963e141d8665a07a8a07cab8159b74a66aabe74 /src/lib.rs
parentf466739b09be1baffd13110b431ecd8057a40771 (diff)
downloades-public-proxy-780ca2a819a6d1c931580c8e8e31657072971876.tar.gz
es-public-proxy-780ca2a819a6d1c931580c8e8e31657072971876.zip
more progress and tests
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs94
1 files changed, 74 insertions, 20 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 615e4ed..7d26360 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -52,6 +52,7 @@ URL query parameters:
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
#[derive(Serialize, Deserialize, Debug)]
+#[serde(deny_unknown_fields)]
pub struct SearchBody {
pub query: Option<ApiQuery>,
pub highlight: Option<ApiHighlight>,
@@ -61,13 +62,13 @@ pub struct SearchBody {
// script_fields disabled
// https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html
- // pub sort: Option<Vec<SortThing>>, // XXX: array of object or string
+ pub sort: Option<Vec<SortElement>>,
pub slice: Option<ApiSlice>,
pub stored_fields: Option<String>, // array of strings, or "_none_"
// overlap with URL query parameters
- pub docvalue_fields: Option<Vec<String>>, // XXX: array of strings or objects? {field, format} in the objects
+ pub docvalue_fields: Option<Vec<DocValOrString>>,
pub explain: Option<bool>,
pub from: Option<u32>,
pub min_score: Option<f64>,
@@ -81,6 +82,13 @@ pub struct SearchBody {
}
#[derive(Serialize, Deserialize, Debug)]
+#[serde(deny_unknown_fields)]
+pub struct ScrollBody {
+ pub scroll_id: String,
+ pub scroll: Option<String>,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
pub struct ApiSlice {
id: u32,
max: u32,
@@ -93,31 +101,26 @@ pub struct ApiRescore{
pub window_size: Option<u32>,
}
+// TODO: could revert to having query types as an enum, with flattening
#[derive(Serialize, Deserialize, Debug)]
-pub enum ApiQuery {
+pub struct ApiQuery {
// compound queries
#[serde(rename = "bool")]
- Bool(HashMap<String, QueryFieldOrString>),
- #[serde(rename = "boosting")]
- Boosting {positive: Box<ApiQuery>, negative: Box<ApiQuery>, negative_boost: f64},
- #[serde(rename = "constant_score")]
- ConstantScore {filter: Box<ApiQuery>, boost: Option<f64>},
+ bool_query: Option<BoolQuery>,
+ boosting: Option<BoostingQuery>,
+ constant_score: Option<ConstantScoreQuery>,
// fulltext (leaf) queries
// term-level (leaf) queries
#[serde(rename = "match")]
- Match(HashMap<String, QueryFieldOrString>),
- #[serde(rename = "match_phrase")]
- MatchPhrase(HashMap<String, QueryFieldOrString>),
- #[serde(rename = "query_string")]
- QueryString(QueryField),
+ match_query: Option<HashMap<String, QueryFieldOrString>>,
+ match_phrase: Option<HashMap<String, QueryFieldOrString>>,
+ query_string: Option<QueryField>,
// other
- #[serde(rename = "nested")]
- Nested(NestedQuery),
- #[serde(rename = "rescore_query")]
- Rescore(Box<ApiQuery>),
+ nested: Option<NestedQuery>,
+ rescore_query: Option<Box<ApiQuery>>,
}
#[derive(Serialize, Deserialize, Debug)]
@@ -131,6 +134,27 @@ pub struct ApiHighlight{
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
+pub enum SortMapValue {
+ String(String),
+ Object { order: String, mode: Option<String> },
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+#[serde(untagged)]
+pub enum SortElement{
+ String(String),
+ Object(HashMap<String, SortMapValue>),
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+#[serde(untagged)]
+pub enum DocValOrString {
+ String(String),
+ Object {field: String, format: Option<String>},
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+#[serde(untagged)]
pub enum QueryFieldOrString {
Object(QueryField),
String(String),
@@ -145,13 +169,36 @@ pub struct QueryField{
}
#[derive(Serialize, Deserialize, Debug)]
-pub struct NestedQuery{
+pub struct BoolQuery {
+ must: Option<Box<ApiQuery>>,
+ filter: Option<Box<ApiQuery>>,
+ should: Option<Box<ApiQuery>>,
+ must_not: Option<Box<ApiQuery>>,
+ minimum_should_match: Option<u32>,
+ boost: Option<f64>,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct NestedQuery {
path: String,
query: Box<ApiQuery>,
score_mode: Option<String>,
ignore_unmapped: Option<bool>,
}
+#[derive(Serialize, Deserialize, Debug)]
+pub struct BoostingQuery {
+ positive: Box<ApiQuery>,
+ negative: Box<ApiQuery>,
+ negative_boost: f64,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct ConstantScoreQuery {
+ filter: Box<ApiQuery>,
+ boost: Option<f64>,
+}
+
// https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html
#[derive(Serialize, Deserialize, Debug)]
pub struct HighlightField{
@@ -181,13 +228,20 @@ pub struct HighlightField{
#[derive(Serialize, Deserialize, Debug)]
pub struct ApiCollapse{
field: String,
- inner_hits: Option<InnerHits>,
+ inner_hits: Option<InnerHitsOneOrMore>,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+#[serde(untagged)]
+pub enum InnerHitsOneOrMore {
+ Single(InnerHits),
+ Multiple(Vec<InnerHits>),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct InnerHits {
from: Option<u32>,
size: Option<u32>,
- sort: Option<Vec<String>>,
+ sort: Option<Vec<SortElement>>,
name: Option<String>,
}