summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs94
-rw-r--r--tests/files/scroll/DELETE_scroll_body.txt (renamed from tests/files/DELETE_scroll_body.txt)0
-rw-r--r--tests/files/scroll/DELETE_scroll_path.txt (renamed from tests/files/DELETE_scroll_path.txt)0
-rw-r--r--tests/files/scroll/POST_scroll_continue.txt (renamed from tests/files/POST_scroll_continue.txt)0
-rw-r--r--tests/parse_es_requests.rs23
5 files changed, 95 insertions, 22 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>,
}
diff --git a/tests/files/DELETE_scroll_body.txt b/tests/files/scroll/DELETE_scroll_body.txt
index 26960a9..26960a9 100644
--- a/tests/files/DELETE_scroll_body.txt
+++ b/tests/files/scroll/DELETE_scroll_body.txt
diff --git a/tests/files/DELETE_scroll_path.txt b/tests/files/scroll/DELETE_scroll_path.txt
index 7910ed8..7910ed8 100644
--- a/tests/files/DELETE_scroll_path.txt
+++ b/tests/files/scroll/DELETE_scroll_path.txt
diff --git a/tests/files/POST_scroll_continue.txt b/tests/files/scroll/POST_scroll_continue.txt
index 9aef4d3..9aef4d3 100644
--- a/tests/files/POST_scroll_continue.txt
+++ b/tests/files/scroll/POST_scroll_continue.txt
diff --git a/tests/parse_es_requests.rs b/tests/parse_es_requests.rs
index 57be06a..a4950c0 100644
--- a/tests/parse_es_requests.rs
+++ b/tests/parse_es_requests.rs
@@ -1,7 +1,7 @@
use std::fs;
use std::ffi::OsStr;
-use es_public_proxy::SearchBody;
+use es_public_proxy::{ScrollBody, SearchBody};
mod common;
@@ -22,7 +22,7 @@ fn basic_parse() {
}
#[test]
-fn parse_all_requests() {
+fn parse_search_requests() {
let file_paths = fs::read_dir("tests/files").unwrap();
@@ -39,3 +39,22 @@ fn parse_all_requests() {
}
}
}
+
+#[test]
+fn parse_scroll_requests() {
+
+ let file_paths = fs::read_dir("tests/files/scroll").unwrap();
+
+ for path in file_paths {
+ let path = path.unwrap().path();
+ if path.extension() != Some(OsStr::new("txt")) {
+ continue
+ }
+ let request = common::load_request(&path);
+ if let Some(body) = request.body {
+ println!("parsing: {}", path.display());
+ println!("BODY: {}", body);
+ let _parsed: ScrollBody = serde_json::from_str(&body).unwrap();
+ }
+ }
+}