Documentation ¶
Overview ¶
Package elastic_proxy provides facilities to translate queries for Elastic Search JSON and SQL-style queries for Sneller engine.
Index ¶
- Constants
- Variables
- func ConvertION(v any) any
- func ExecuteQuery(client *http.Client, u *url.URL, token, sql string) (*http.Response, error)
- func NewElasticFloat(v any) (elasticFloat, error)
- func ParseDateMath(data string, now time.Time) (time.Time, error)
- func ParseExprFieldName(qc *QueryContext, fieldName string) *exprFieldName
- func ParseExprFieldNameAlias(qc *QueryContext, alias, fieldName string) *exprFieldNameAlias
- func ParseExprFieldNameParts(qc *QueryContext, fields []string) *exprFieldName
- func ParseExprSourceName(qc *QueryContext, source string) *exprSourceName
- func ParseExprSourceNameWithAlias(qc *QueryContext, source, alias string) *exprSourceName
- func PrintExpr(e expression) string
- func PrintExprPretty(e expression) string
- type AggregationStrategy
- type ElasticJSON
- type ElasticMapping
- type ElasticResult
- type JSONLiteral
- type MappingValue
- type Operator
- type Ordering
- type Properties
- type Query
- type QueryContext
- type QueryString
- type Range
- type SortField
- type TableSource
- type TrackTotalHits
- type TypeMapping
- type ZeroTermsQuery
Constants ¶
View Source
const ( TotalCountBucket = "$total_count" HitsBucket = "$hits" KeyPrefix = "$key" BucketPrefix = "$bucket" DocCount = "$doc_count" DefaultSource = "$source" SourceAliasPrefix = "$source:" )
View Source
const ( LatExt = ".lat" LonExt = ".lon" )
View Source
const ( OrderAscending = "ASC" OrderDescending = "DESC" )
View Source
const DefaultElasticUser = "elastic"
View Source
const (
DefaultHTTPTimeout time.Duration = 30 * time.Second
)
View Source
const DummyAlias = "$dummy$"
Variables ¶
View Source
var ( ErrNoFieldName = errors.New("no fieldname set") ErrInvalidRegexOperator = errors.New("invalid regex operator") )
View Source
var ( ErrNotSupported = errors.New("unsupported element") ErrUnsupportedNumber = errors.New("unsupported number") ErrTermOnlySingleField = errors.New("term supports only a single field") )
View Source
var DefaultTrackTotalHits = TrackTotalHits{ Enabled: true, Limit: 10000, }
View Source
var (
ErrInvalidUnit = errors.New("invalid unit")
)
View Source
var (
ErrUnsupportedLiteralType = errors.New("unsupported literal type")
)
Functions ¶
func ConvertION ¶
func ExecuteQuery ¶
func NewElasticFloat ¶
func ParseExprFieldName ¶
func ParseExprFieldName(qc *QueryContext, fieldName string) *exprFieldName
func ParseExprFieldNameAlias ¶
func ParseExprFieldNameAlias(qc *QueryContext, alias, fieldName string) *exprFieldNameAlias
func ParseExprFieldNameParts ¶
func ParseExprFieldNameParts(qc *QueryContext, fields []string) *exprFieldName
func ParseExprSourceName ¶
func ParseExprSourceName(qc *QueryContext, source string) *exprSourceName
func ParseExprSourceNameWithAlias ¶
func ParseExprSourceNameWithAlias(qc *QueryContext, source, alias string) *exprSourceName
func PrintExprPretty ¶
func PrintExprPretty(e expression) string
Types ¶
type AggregationStrategy ¶
type AggregationStrategy int
const ( // // Perform single scan over the data while // building full tree for all aggregation // levels and prune back when done. // (Consumes more memory and typically // faster) SingleScan AggregationStrategy = iota // // Perform more than one scan and prune // back interim results after each pass. // (Consumes more memory and typically // slower) MultiScan )
type ElasticJSON ¶
type ElasticJSON struct { From *int `json:"from"` Size *int `json:"size"` Aggregations map[string]aggregation `json:"aggs"` Sort []SortField `json:"sort"` Query *Query `json:"query"` Version *bool `json:"version"` // indicates it the version should be included in the hit Source *source `json:"_source"` // indicates if source record should be included in the hit Fields []projectedField `json:"fields"` TrackTotalHits *TrackTotalHits `json:"track_total_hits"` }
func (*ElasticJSON) ConvertResult ¶
func (ej *ElasticJSON) ConvertResult(qc *QueryContext, snellerResult map[string]any) (*ElasticResult, map[string]any, error)
func (*ElasticJSON) SQL ¶
func (ej *ElasticJSON) SQL(qc *QueryContext) (*exprSelect, error)
type ElasticMapping ¶
type ElasticMapping struct {
Properties Properties `json:"properties"`
}
ElasticMapping represents type mappings used by ElasticSearch
func DataShapeToElasticMapping ¶
func DataShapeToElasticMapping(fields map[string]any) *ElasticMapping
DataShapeToElasticMapping translates raw 'fields' output from SNELLER_DATASHAPE into Elastic's Mapping structure.
type ElasticResult ¶
type JSONLiteral ¶
type JSONLiteral struct { // string, bool or float64 Value any }
func NewJSONLiteral ¶
func NewJSONLiteral(v any) (JSONLiteral, error)
func (*JSONLiteral) String ¶
func (jl *JSONLiteral) String() string
func (*JSONLiteral) UnmarshalJSON ¶
func (jl *JSONLiteral) UnmarshalJSON(data []byte) error
type MappingValue ¶
type MappingValue struct { Type string `json:"type"` Indexed bool `json:"indexed,omitempty"` Properties Properties `json:"properties,omitempty"` }
type Properties ¶
type Properties map[string]MappingValue
type Query ¶
type Query struct { // https://www.elastic.co/guide/en/elasticsearch/reference/current/compound-queries.html Bool *boolean `json:"bool"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html Boosting *notSupported `json:"boosting"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html ConstantScore *constantScore `json:"constant_score"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html DisMax *notSupported `json:"dis_max"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html FunctionScore *notSupported `json:"function_score"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html // https://www.elastic.co/guide/en/elasticsearch/reference/current/full-text-queries.html Intervals *notSupported `json:"intervals"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-intervals-query.html Match *match `json:"match"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html MatchBoolPrefix *map[string]field `json:"match_bool_prefix"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-bool-prefix-query.html MatchPhrase *matchPhrase `json:"match_phrase"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html MatchPhrasePrefix *map[string]field `json:"match_phrase_prefix"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html CombinedFields *map[string]field `json:"combined_fields"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-combined-fields-query.html MultiMatch *map[string]field `json:"multi_match"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html QueryString *QueryString `json:"query_string"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html SimpleQueryString *notSupported `json:"simple_query_string"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html // https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-queries.html GeoBoundingBox *geoBoundingBox `json:"geo_bounding_box"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html GeoDistance *notSupported `json:"geo_distance"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html GeoPolygon *notSupported `json:"geo_polygon"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html GeoShape *notSupported `json:"geo_shape"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html // https://www.elastic.co/guide/en/elasticsearch/reference/current/shape-queries.html Shape *notSupported `json:"shape"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-shape-query.html // https://www.elastic.co/guide/en/elasticsearch/reference/current/joining-queries.html Nested *notSupported `json:"nested"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html HasChild *notSupported `json:"has_child"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html HasParent *notSupported `json:"has_parent"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html ParentID *notSupported `json:"parent_id"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-parent-id-query.html // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html MatchAll *matchAll `json:"match_all"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html#query-dsl-match-all-query MatchNone *matchNone `json:"match_none"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html#query-dsl-match-none-query // https://www.elastic.co/guide/en/elasticsearch/reference/current/span-queries.html SpanContaining *notSupported `json:"span_containing"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-containing-query.html SpanFieldMasking *notSupported `json:"span_field_masking"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-field-masking-query.html SpanFirst *notSupported `json:"span_first"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html SpanMulti *notSupported `json:"span_multi"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-multi-term-query.html SpanNear *notSupported `json:"span_near"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-near-query.html SpanNot *notSupported `json:"span_not"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-not-query.html SpanOr *notSupported `json:"span_or"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-or-query.html SpanTerm *notSupported `json:"span_term"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-term-query.html SpanWithin *notSupported `json:"span_within"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-within-query.html // https://www.elastic.co/guide/en/elasticsearch/reference/current/specialized-queries.html DistanceFeature *notSupported `json:"distance_feature"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-distance-feature-query.html MoreLikeThis *notSupported `json:"more_like_this"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html Percolate *notSupported `json:"percolate"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-percolate-query.html RankFeature *notSupported `json:"rank_feature"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-rank-feature-query.html Script *notSupported `json:"script"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-query.html ScriptScore *notSupported `json:"script_score"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-score-query.html Wrapper *notSupported `json:"wrapper"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wrapper-query.html Pinned *notSupported `json:"pinned"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-pinned-query.html // https://www.elastic.co/guide/en/elasticsearch/reference/current/term-level-queries.html Exists *exists `json:"exists"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html Fuzzy *notSupported `json:"fuzzy"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html Prefix *notSupported `json:"prefix"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html Range *ranges `json:"range"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html Regexp *notSupported `json:"regexp"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html Term *term `json:"term"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html Terms *terms `json:"terms"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html TermsSet *notSupported `json:"terms_set"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-set-query.html Wildcard *wildCard `json:"wildcard"` // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html }
Query implements the parsing and expression logic for the Elastic Query.
The parser canonicalizes all the input, so all deprecated or shortened representations should be handled by the `UnmarshalJSON` method.
func (*Query) Expression ¶
func (q *Query) Expression(qc *QueryContext) (expression, error)
Expression obtains the full expression (that can be converted) to a SQL WHERE clause for the query
type QueryContext ¶
type QueryContext struct { Query ElasticJSON Index string TableSources []TableSource Sources []expression IgnoreTotalHits bool IgnoreSumOtherDocCount bool TypeMapping map[string]TypeMapping }
type QueryString ¶
type QueryString struct { Query string `json:"query"` DefaultField *string `json:"default_field"` AllowLeadingWildcard *bool `json:"allow_leading_wildcard"` AnalyzeWildcard *bool `json:"analyze_wildcard"` Analyzer *string `json:"analyzer"` AutoGenerateSynonymsPhraseQuery *bool `json:"auto_generate_synonyms_phrase_query"` Boost *boostValue `json:"boost"` DefaultOperator *string `json:"default_operator"` EnablePositionIncrements *bool `json:"enable_position_increments"` Fields *[]string `json:"fields"` Fuzziness *string `json:"fuzziness"` FuzzyMaxExpansions *int `json:"fuzzy_max_expansions"` FuzzyPrefixLength *int `json:"fuzzy_prefix_length"` FuzzyTranspositions *bool `json:"fuzzy_transpositions"` Lenient *bool `json:"lenient"` MaxDeterminizedStates *int `json:"max_determinized_states"` MinimumShouldMatch *string `json:"minimum_should_match"` QuoteAnalyzer *string `json:"quote_analyzer"` PhraseSlop *int `json:"phrase_slop"` QuoteFieldSuffix *string `json:"quote_field_suffix"` Rewrite *string `json:"rewrite"` TimeZone *string `json:"time_zone"` }
func (*QueryString) Expression ¶
func (qs *QueryString) Expression(qc *QueryContext) (expression, error)
type Range ¶
type Range struct { GreaterThan *JSONLiteral `json:"gt"` GreaterThanOrEqualTo *JSONLiteral `json:"gte"` LessThan *JSONLiteral `json:"lt"` LessThanOrEqualTo *JSONLiteral `json:"lte"` Format *string `json:"format"` Relation *string `json:"relation"` TimeZone *string `json:"time_zone"` Boost *boostValue `json:"boost"` }
func (*Range) UnmarshalJSON ¶
type TableSource ¶
type TableSource struct {
Database, Table string
}
type TrackTotalHits ¶
type TrackTotalHits struct { Enabled bool // set if hits need to be returned Limit int64 // max nr. of items (-1: exact count) }
func (*TrackTotalHits) UnmarshalJSON ¶
func (sf *TrackTotalHits) UnmarshalJSON(data []byte) error
type TypeMapping ¶
type TypeMapping struct { Type string `json:"type"` Fields map[string]string `json:"fields,omitempty"` }
func (*TypeMapping) UnmarshalJSON ¶
func (tm *TypeMapping) UnmarshalJSON(data []byte) error
type ZeroTermsQuery ¶
type ZeroTermsQuery string
const ( ZeroTermsQueryNone ZeroTermsQuery = "none" ZeroTermsQueryAll ZeroTermsQuery = "all" )
Source Files ¶
- aggs.go
- aggs_avg.go
- aggs_bucket_script.go
- aggs_bucket_sort.go
- aggs_cardinality.go
- aggs_date_histogram.go
- aggs_filter.go
- aggs_filters.go
- aggs_generate_context.go
- aggs_geo_centroid.go
- aggs_geotile_grid.go
- aggs_histogram.go
- aggs_max.go
- aggs_min.go
- aggs_multi_terms.go
- aggs_process_context.go
- aggs_sum.go
- aggs_terms.go
- aggs_top_hits.go
- aggs_value_count.go
- calendar_interval.go
- const.go
- date_math.go
- date_math_lexer.rl
- doc.go
- elastic_json.go
- elastic_mapping.go
- executeQuery.go
- expr.go
- fixed_interval.go
- geo_helpers.go
- helpers.go
- json_literal.go
- order.go
- parse_ion.go
- qs.go
- qs_lexer.rl
- qs_parser.go
- query.go
- query_context.go
- time_offset.go
- type_format.go
- type_mapping.go
Click to show internal directories.
Click to hide internal directories.