From 780ca2a819a6d1c931580c8e8e31657072971876 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 24 Aug 2020 14:13:56 -0700 Subject: more progress and tests --- src/lib.rs | 94 +++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 20 deletions(-) (limited to 'src') 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, pub highlight: Option, @@ -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>, // XXX: array of object or string + pub sort: Option>, pub slice: Option, pub stored_fields: Option, // array of strings, or "_none_" // overlap with URL query parameters - pub docvalue_fields: Option>, // XXX: array of strings or objects? {field, format} in the objects + pub docvalue_fields: Option>, pub explain: Option, pub from: Option, pub min_score: Option, @@ -80,6 +81,13 @@ pub struct SearchBody { // not enumerated in direct docs, but seems to be allowed? } +#[derive(Serialize, Deserialize, Debug)] +#[serde(deny_unknown_fields)] +pub struct ScrollBody { + pub scroll_id: String, + pub scroll: Option, +} + #[derive(Serialize, Deserialize, Debug)] pub struct ApiSlice { id: u32, @@ -93,31 +101,26 @@ pub struct ApiRescore{ pub window_size: Option, } +// 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), - #[serde(rename = "boosting")] - Boosting {positive: Box, negative: Box, negative_boost: f64}, - #[serde(rename = "constant_score")] - ConstantScore {filter: Box, boost: Option}, + bool_query: Option, + boosting: Option, + constant_score: Option, // fulltext (leaf) queries // term-level (leaf) queries #[serde(rename = "match")] - Match(HashMap), - #[serde(rename = "match_phrase")] - MatchPhrase(HashMap), - #[serde(rename = "query_string")] - QueryString(QueryField), + match_query: Option>, + match_phrase: Option>, + query_string: Option, // other - #[serde(rename = "nested")] - Nested(NestedQuery), - #[serde(rename = "rescore_query")] - Rescore(Box), + nested: Option, + rescore_query: Option>, } #[derive(Serialize, Deserialize, Debug)] @@ -129,6 +132,27 @@ pub struct ApiHighlight{ settings: HighlightField, } +#[derive(Serialize, Deserialize, Debug)] +#[serde(untagged)] +pub enum SortMapValue { + String(String), + Object { order: String, mode: Option }, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(untagged)] +pub enum SortElement{ + String(String), + Object(HashMap), +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(untagged)] +pub enum DocValOrString { + String(String), + Object {field: String, format: Option}, +} + #[derive(Serialize, Deserialize, Debug)] #[serde(untagged)] pub enum QueryFieldOrString { @@ -145,13 +169,36 @@ pub struct QueryField{ } #[derive(Serialize, Deserialize, Debug)] -pub struct NestedQuery{ +pub struct BoolQuery { + must: Option>, + filter: Option>, + should: Option>, + must_not: Option>, + minimum_should_match: Option, + boost: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct NestedQuery { path: String, query: Box, score_mode: Option, ignore_unmapped: Option, } +#[derive(Serialize, Deserialize, Debug)] +pub struct BoostingQuery { + positive: Box, + negative: Box, + negative_boost: f64, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ConstantScoreQuery { + filter: Box, + boost: Option, +} + // 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, + inner_hits: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(untagged)] +pub enum InnerHitsOneOrMore { + Single(InnerHits), + Multiple(Vec), } #[derive(Serialize, Deserialize, Debug)] pub struct InnerHits { from: Option, size: Option, - sort: Option>, + sort: Option>, name: Option, } -- cgit v1.2.3