summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-08-24 13:43:13 -0700
committerBryan Newbold <bnewbold@archive.org>2020-08-24 13:43:28 -0700
commitf466739b09be1baffd13110b431ecd8057a40771 (patch)
tree903484b612c3a55e4a14e826f689930f23e4b1e9 /src
parent03bb85c57086e4371d827b5fbd496d3e820496b7 (diff)
downloades-public-proxy-f466739b09be1baffd13110b431ecd8057a40771.tar.gz
es-public-proxy-f466739b09be1baffd13110b431ecd8057a40771.zip
WIP: expanding query parsing
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs172
1 files changed, 165 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 1ba6207..615e4ed 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,35 +1,193 @@
use serde::{Serialize, Deserialize};
+use std::collections::HashMap;
#[derive(Serialize, Deserialize, Debug)]
pub struct ApiRequest {
pub method: String,
pub path_and_query: String,
- pub body: Option<ApiBody>,
+ pub body: Option<SearchBody>,
}
+/*
+
+URL query parameters:
+
+ pub allow_no_indices: Option<bool>,
+ pub allow_partial_search_results: Option<bool>,
+ pub batched_reduce_size: Option<u32>,
+ pub ccs_minimize_roundtrips: Option<bool>,
+ pub docvalue_fields: Option<String>, // array of strings, comma-separated
+ pub expand_wildcards: Option<String>,
+ pub explain: Option<bool>,
+ pub from: Option<u32>,
+ pub ignore_throttled: Option<bool>,
+ pub ignore_unavailable: Option<bool>,
+ pub max_concurrent_shard_requests: Option<u32>,
+ pub pre_filter_shard_size: Option<u32>,
+ pub preference: Option<String>,
+ pub q: Option<String>
+ pub request_cache: Option<bool>,
+ pub rest_total_hits_as_int: Option<bool>,
+ pub routing: Option<String>,
+ pub scroll: Option<String>, // string is "time value"
+ pub search_type: Option<String>,
+ pub seq_no_primary_term: Option<bool>,
+ pub size: Option<u32>,
+ pub sort: Option<String>, // array of strings, comma-separated
+ pub _source: Option<bool>, // TODO: bool or string
+ pub _source_excludes: Option<String>, // array of strings, comma-separated
+ pub _source_includes: Option<String>, // array of strings, comma-separated
+ pub stats: Option<String>,
+ pub stored_fields: Option<String>, // array of strings, comma-separated
+ pub suggest_field: Option<String>,
+ pub suggest_text: Option<String>,
+ pub terminate_after: Option<u32>,
+ pub timeout: Option<String>, // string is "time units"
+ pub track_scores: Option<bool>,
+ pub track_total_hits: Option<bool>, // XXX: bool or integer
+ pub typed_keys: Option<bool>,
+ pub version: Option<bool>,
+*/
+
+// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
#[derive(Serialize, Deserialize, Debug)]
-pub struct ApiBody {
+pub struct SearchBody {
pub query: Option<ApiQuery>,
+ pub highlight: Option<ApiHighlight>,
+ pub collapse: Option<ApiCollapse>,
+ pub post_filter: Option<ApiQuery>, // TODO: leaf query only?
+ pub rescore: Option<ApiRescore>, // TODO: single or an array of rescore objects
+ // 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 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 explain: Option<bool>,
pub from: Option<u32>,
+ pub min_score: Option<f64>,
+ pub seq_no_primary_term: Option<bool>,
pub size: Option<u32>,
- pub sort: Option<String>, // XXX
- pub slice: Option<String>, // XXX
+ pub _source: Option<bool>, // XXX: bool, string, or object
+ pub terminate_after: Option<u32>,
+ pub timeout: Option<String>, // string is "time units"
+
+ // not enumerated in direct docs, but seems to be allowed?
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct ApiSlice {
+ id: u32,
+ max: u32,
+ field: Option<String>,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct ApiRescore{
+ pub query: Option<ApiQuery>,
+ pub window_size: Option<u32>,
}
#[derive(Serialize, Deserialize, Debug)]
pub enum 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>},
+
+ // fulltext (leaf) queries
+
+ // term-level (leaf) queries
#[serde(rename = "match")]
- Match(MatchQuery),
+ Match(HashMap<String, QueryFieldOrString>),
+ #[serde(rename = "match_phrase")]
+ MatchPhrase(HashMap<String, QueryFieldOrString>),
+ #[serde(rename = "query_string")]
+ QueryString(QueryField),
+
+ // other
+ #[serde(rename = "nested")]
+ Nested(NestedQuery),
+ #[serde(rename = "rescore_query")]
+ Rescore(Box<ApiQuery>),
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct ApiHighlight{
+ // TODO: fields could also be an array of strings?
+ fields: HashMap<String, HighlightField>,
+
+ #[serde(flatten)]
+ settings: HighlightField,
}
#[derive(Serialize, Deserialize, Debug)]
-pub struct MatchQuery {
- message: QueryField,
+#[serde(untagged)]
+pub enum QueryFieldOrString {
+ Object(QueryField),
+ String(String),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct QueryField{
query: String,
fuzziness: Option<String>,
+ slop: 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>,
+}
+
+// https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html
+#[derive(Serialize, Deserialize, Debug)]
+pub struct HighlightField{
+ boundary_chars: Option<String>,
+ boundary_max_scan: Option<u32>,
+ boundary_scanner: Option<String>,
+ boundary_scanner_locale: Option<String>,
+ encoder: Option<String>,
+ force_source: Option<bool>,
+ fragmenter: Option<String>,
+ fragment_offset: Option<u32>,
+ fragment_size: Option<u32>,
+ highlight_query: Option<ApiQuery>,
+ matched_fields: Option<Vec<String>>,
+ no_match_size: Option<u32>,
+ number_of_fragments: Option<u32>,
+ order: Option<String>,
+ phrase_limit: Option<u32>,
+ pre_tags: Option<Vec<String>>,
+ post_tags: Option<Vec<String>>,
+ require_field_match: Option<bool>,
+ tags_schema: Option<String>,
+ #[serde(rename = "type")]
+ highlight_type: Option<String>,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct ApiCollapse{
+ field: String,
+ inner_hits: Option<InnerHits>,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct InnerHits {
+ from: Option<u32>,
+ size: Option<u32>,
+ sort: Option<Vec<String>>,
+ name: Option<String>,
}