diff --git a/search/opensearch_types.go b/search/opensearch_types.go index 896541be6658c549b0ce4e57b22dd67f1a0cb6e0..8e52f073ab265d379c9978dcf78c460cc85c5cd0 100644 --- a/search/opensearch_types.go +++ b/search/opensearch_types.go @@ -39,28 +39,42 @@ type SearchRequestBody struct { Timeout string `json:"timeout,omitempty"` // timeout for search } -// Query NOTE: We are only using bool filter queries, to be able to always do the correct sorting, not based on the relevancy score // https://opensearch.org/docs/latest/opensearch/query-dsl/bool/ type Query struct { - Bool *QueryBool `json:"bool,omitempty"` + Match *QueryMatch `json:"match,omitempty" doc:"<field>:<value>"` + Term *QueryTerm `json:"term,omitempty"` + Range *QueryRange `json:"range,omitempty"` + MultiMatch *QueryMultiMatch `json:"multi_match,omitempty"` + Bool *QueryBool `json:"bool,omitempty"` + QueryString *QueryString `json:"query_string,omitempty"` + SimpleQueryString *QueryString `json:"simple_query_string,omitempty"` } type QueryBool struct { - Must []FilterQuery `json:"must,omitempty"` // List of things that must appear in matching documents and will contribute to the score. - Filter []FilterQuery `json:"filter,omitempty"` // List of things that must appear in matching documents. However, unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching - Should []Query `json:"should,omitempty"` // List of things that should appear in the matching document. - MustNot []FilterQuery `json:"must_not,omitempty"` // List of things that must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned + Must []FilterQuery `json:"must,omitempty"` // List of things that must appear in matching documents and will contribute to the score. + Filter []FilterQuery `json:"filter,omitempty"` // List of things that must appear in matching documents. However, unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching + Should []Query `json:"should,omitempty"` // List of things that should appear in the matching document. + MustNot []FilterQuery `json:"must_not,omitempty"` // List of things that must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned + MinimumShouldMatch int64 `json:"minimum_should_match"` } type FilterQuery struct { // one of: - Match *QueryMatch `json:"match,omitempty"` - Term *QueryTerm `json:"term,omitempty"` - Range *QueryRange `json:"range,omitempty"` - MultiMatch *QueryMultiMatch `json:"multi_match,omitempty"` - Bool *QueryBool `json:"bool,omitempty"` - QueryString *QueryString `json:"query_string,omitempty"` - Wildcard *QueryWildcard `json:"wildcard,omitempty"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html + Match *QueryMatch `json:"match,omitempty"` + Term *QueryTerm `json:"term,omitempty"` + Range *QueryRange `json:"range,omitempty"` + MultiMatch *QueryMultiMatch `json:"multi_match,omitempty"` + Bool *QueryBool `json:"bool,omitempty"` + QueryString *QueryString `json:"query_string,omitempty"` + SimpleQueryString *QueryString `json:"simple_query_string,omitempty"` + Wildcard *QueryWildcard `json:"wildcard,omitempty"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html +} + +type QueryValue struct { + Query string `json:"query"` + Operator string `json:"operator,omitempty"` // defaults to "or", accepted values: or|and + Fuzziness string `json:"fuzziness,omitempty"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#fuzziness + ZeroTermsQuery string `json:"zero_terms_query,omitempty"` } type QueryMatch map[string]string @@ -70,20 +84,23 @@ type QueryTerm map[string]string type QueryWildcard map[string]string type QueryMultiMatch struct { - Query string `json:"query"` // Full value match search in selected fields - Fields []string `json:"fields,omitempty" doc:"List of fields"` - Type QueryMultiMatchType `json:"type,omitempty"` + Query string `json:"query"` // Full value match search in selected fields + Fields []string `json:"fields,omitempty" doc:"List of fields"` + Type QueryMultiMatchType `json:"type,omitempty"` + Operator string `json:"operator,omitempty"` } type QueryMultiMatchType string const ( - QueryMultiMatchTypePhrase QueryMultiMatchType = "phrase" + QueryMultiMatchTypePhrase QueryMultiMatchType = "phrase" + QueryMultiMatchTypeCrossFields QueryMultiMatchType = "cross_fields" ) type QueryString struct { - Query string `json:"query"` // Text search with partial matches, using asterisk for optional or question mark for required wildcards before and/or after text - Fields []string `json:"fields,omitempty" doc:"List of fields"` + Query string `json:"query"` // Text search with partial matches, using asterisk for optional or question mark for required wildcards before and/or after text + Fields []string `json:"fields,omitempty" doc:"List of fields"` + DefaultOperator string `json:"default_operator,omitempty"` } type QueryRange map[string]QueryExpr