Documentation ¶
Index ¶
- Constants
- func BuildCurrentIndex(tenant uuid.UUID, elements ...string) string
- func BuildIndex(tenant uuid.UUID, date time.Time, elements ...string) string
- func BuildIndexPattern(tenant uuid.UUID, elements ...string) string
- func Bulk(ctx context.Context, items []BulkItem) error
- func Connect(nodes []string) error
- func IndexDoc(ctx context.Context, doc interface{}, index, id string) error
- type Agg
- type Aggs
- type Bool
- type BulkItem
- type Cardinality
- type Collapse
- type DateRange
- type ExtendedStats
- type GeoDistance
- type Grid
- type Header
- type Histogram
- type Hit
- type HitSource
- type Hits
- type IndexAction
- type Match
- type MatchBoolPrefix
- type MatchPhrase
- type MatchPhrasePrefix
- type MovingAvg
- type MultiMatch
- type MultiTerms
- type PercentileRanks
- type PipelineAgg
- type Query
- type QueryString
- type Range
- type SearchRequest
- type SearchResult
- type SerialDiff
- type Shards
- type SimpleQueryString
- type Source
- type Terms
- type TopHits
- type Total
- type Update
Constants ¶
const ( EventSubstr string = "events" AlertSubstr string = "alerts" RelationSubstr string = "relations" )
Variables ¶
This section is empty.
Functions ¶
func BuildCurrentIndex ¶
BuildCurrentIndex returns a string representing the current index based on the given elements.
func BuildIndex ¶
BuildIndex returns a string representing an index based on the given date and elements.
func BuildIndexPattern ¶
BuildIndexPattern returns a string representing an index pattern based on the given elements.
func Bulk ¶ added in v0.11.15
Bulk sends a bulk request to the OpenSearch server with the provided items. It takes a context and a slice of BulkItem as parameters and returns an error if any occurs.
The BulkItem struct contains the following fields: - Index: The index name where the document will be stored. - Id: The document ID. - Body: The document content in byte slice format. - Action: The action to be performed (e.g., "index").
The function constructs a bulk request by iterating over the items and creating the necessary JSON payload for each item based on its action. Currently, only the "index" action is supported.
The function then sends the bulk request to the OpenSearch server using the opensearchapi.BulkRequest and checks the response status code. If the status code indicates an error, it reads the response body and returns an error with the status code and response body.
Parameters: - ctx: The context for the request. - items: A slice of BulkItem containing the items to be indexed.
Returns: - error: An error if any occurs during the request or response processing.
func IndexDoc ¶
IndexDoc indexes a document in OpenSearch. It takes a document, an index name, and an ID as input parameters. The document is marshalled to JSON and sent to OpenSearch for indexing. Returns an error if there is an issue with marshalling the document to JSON, if there is an issue with the request to OpenSearch, or if the response status code is not 200, 201, or 202.
Types ¶
type Aggs ¶
type Aggs struct { Aggs map[string]Aggs `json:"aggs,omitempty"` Avg *Agg `json:"avg,omitempty"` Sum *Agg `json:"sum,omitempty"` Min *Agg `json:"min,omitempty"` Max *Agg `json:"max,omitempty"` Cardinality *Cardinality `json:"cardinality,omitempty"` ValueCount *Agg `json:"value_count,omitempty"` Stats *Agg `json:"stats,omitempty"` ExtendedStats *ExtendedStats `json:"extended_stats,omitempty"` MatrixStats map[string][]string `json:"matrix_stats,omitempty"` Percentiles *Agg `json:"percentiles,omitempty"` PercentileRanks *PercentileRanks `json:"percentile_ranks,omitempty"` TopHits *TopHits `json:"top_hits,omitempty"` Terms *Terms `json:"terms,omitempty"` MultiTerms *MultiTerms `json:"multi_terms,omitempty"` Sampler map[string]interface{} `json:"sampler,omitempty"` DiversifiedSampler map[string]interface{} `json:"diversified_sampler,omitempty"` SignificantTerms *Agg `json:"significant_terms,omitempty"` SignificantText map[string]interface{} `json:"significant_text,omitempty"` Histogram *Histogram `json:"histogram,omitempty"` DateHistogram *Histogram `json:"date_histogram,omitempty"` Range *Range `json:"range,omitempty"` DateRange *DateRange `json:"date_range,omitempty"` IPRange *Range `json:"ip_range,omitempty"` Filter map[string]interface{} `json:"filter,omitempty"` Filters map[string]interface{} `json:"filters,omitempty"` Global interface{} `json:"global,omitempty"` Nested map[string]string `json:"nested,omitempty"` ReverseNested interface{} `json:"reverse_nested,omitempty"` SumBucket *PipelineAgg `json:"sum_bucket,omitempty"` AvgBucket *PipelineAgg `json:"avg_bucket,omitempty"` MinBucket *PipelineAgg `json:"min_bucket,omitempty"` MaxBucket *PipelineAgg `json:"max_bucket,omitempty"` StatsBucket *PipelineAgg `json:"stats_bucket,omitempty"` ExtendedStatsBucket *PipelineAgg `json:"extended_stats_bucket,omitempty"` BucketSort map[string]interface{} `json:"bucket_sort,omitempty"` CumulativeSum *PipelineAgg `json:"cumulative_sum,omitempty"` Derivative *PipelineAgg `json:"derivative,omitempty"` MovingAvg *MovingAvg `json:"moving_avg,omitempty"` SerialDiff *SerialDiff `json:"serial_diff,omitempty"` GeoDistance *GeoDistance `json:"geo_distance,omitempty"` GeohashGrid *Grid `json:"geohash_grid,omitempty"` GeohexGrid *Grid `json:"geohex_grid,omitempty"` GeotileGrid *Grid `json:"geotile_grid,omitempty"` AdjacencyMatrix map[string]interface{} `json:"adjacency_matrix,omitempty"` }
type Cardinality ¶
type ExtendedStats ¶
type GeoDistance ¶
type GeoDistance struct { Origin interface{} `json:"origin,omitempty"` Range }
type Histogram ¶
type Histogram struct { Field string `json:"field,omitempty"` Interval interface{} `json:"interval,omitempty"` }
type Hit ¶
type Hit struct { Index string `json:"_index"` ID string `json:"_id"` Version int64 `json:"_version"` Score interface{} `json:"_score"` Source HitSource `json:"_source"` Fields map[string]interface{} `json:"fields"` Sort []int64 `json:"sort"` Found bool `json:"found,omitempty"` }
type HitSource ¶
type HitSource map[string]interface{}
func (HitSource) ParseSource ¶
ParseSource parses the HitSource object into a JSON string and then decode it into the provided destination object. The destination object must be a pointer to the desired type.
type IndexAction ¶ added in v0.11.15
type IndexAction struct {
Index *Header `json:"index,omitempty"`
}
type Match ¶
type Match struct { Query string `json:"query,omitempty"` Fuzziness string `json:"fuzziness,omitempty"` FuzzyTranspositions bool `json:"fuzzy_transpositions,omitempty"` Operator string `json:"operator,omitempty"` MinimumShouldMatch int64 `json:"minimum_should_match,omitempty"` Analyzer string `json:"analyzer,omitempty"` ZeroTermsQuery string `json:"zero_terms_query,omitempty"` Lenient bool `json:"lenient,omitempty"` PrefixLength int64 `json:"prefix_length,omitempty"` MaxExpansions int64 `json:"max_expansions,omitempty"` Boost int64 `json:"boost,omitempty"` }
type MatchBoolPrefix ¶
type MatchBoolPrefix struct { Query string `json:"query,omitempty"` Fuzziness string `json:"fuzziness,omitempty"` FuzzyTranspositions bool `json:"fuzzy_transpositions,omitempty"` MaxExpansions int64 `json:"max_expansions,omitempty"` PrefixLength int64 `json:"prefix_length,omitempty"` Operator string `json:"operator,omitempty"` MinimumShouldMatch int64 `json:"minimum_should_match,omitempty"` Analyzer string `json:"analyzer,omitempty"` }
type MatchPhrase ¶
type MatchPhrasePrefix ¶
type MovingAvg ¶
type MovingAvg struct { Predict int `json:"predict,omitempty"` Window int `json:"window,omitempty"` Model string `json:"model,omitempty"` Settings map[string]interface{} `json:"settings,omitempty"` PipelineAgg }
type MultiMatch ¶
type MultiMatch struct { Query string `json:"query,omitempty"` Fields []string `json:"fields,omitempty"` Fuzziness string `json:"fuzziness,omitempty"` FuzzyTranspositions bool `json:"fuzzy_transpositions,omitempty"` Operator string `json:"operator,omitempty"` MinimumShouldMatch int64 `json:"minimum_should_match,omitempty"` Analyzer string `json:"analyzer,omitempty"` ZeroTermsQuery string `json:"zero_terms_query,omitempty"` Lenient bool `json:"lenient,omitempty"` PrefixLength int64 `json:"prefix_length,omitempty"` MaxExpansions int64 `json:"max_expansions,omitempty"` Boost int64 `json:"boost,omitempty"` Type string `json:"type,omitempty"` TieBreaker float64 `json:"tie_breaker,omitempty"` AutoGenerateSynonymsPhraseQuery bool `json:"auto_generate_synonyms_phrase_query,omitempty"` }
type MultiTerms ¶
type PercentileRanks ¶
type PipelineAgg ¶
type PipelineAgg struct {
BucketsPath string `json:"buckets_path,omitempty"`
}
type Query ¶
type Query struct { Bool *Bool `json:"bool,omitempty"` Term map[string]map[string]interface{} `json:"term,omitempty"` Terms map[string][]interface{} `json:"terms,omitempty"` IDs map[string][]interface{} `json:"ids,omitempty"` Range map[string]map[string]interface{} `json:"range,omitempty"` Exists map[string]string `json:"exists,omitempty"` Prefix map[string]string `json:"prefix,omitempty"` Fuzzy map[string]map[string]interface{} `json:"fuzzy,omitempty"` Wildcard map[string]map[string]interface{} `json:"wildcard,omitempty"` Regexp map[string]string `json:"regexp,omitempty"` Match map[string]Match `json:"match,omitempty"` MultiMatch *MultiMatch `json:"multi_match,omitempty"` MatchBoolPrefix map[string]MatchBoolPrefix `json:"match_bool_prefix,omitempty"` MatchPhrase map[string]MatchPhrase `json:"match_phrase,omitempty"` MatchPhrasePrefix map[string]MatchPhrasePrefix `json:"match_phrase_prefix,omitempty"` QueryString *QueryString `json:"query_string,omitempty"` SimpleQueryString *SimpleQueryString `json:"simple_query_string,omitempty"` }
type QueryString ¶
type QueryString struct { Query string `json:"query,omitempty"` DefaultField string `json:"default_field,omitempty"` Type string `json:"type,omitempty"` Fuzziness string `json:"fuzziness,omitempty"` FuzzyTranspositions bool `json:"fuzzy_transpositions,omitempty"` FuzzyMaxExpansions int64 `json:"fuzzy_max_expansions,omitempty"` FuzzyPrefixLength int64 `json:"fuzzy_prefix_length,omitempty"` MinimumShouldMatch int64 `json:"minimum_should_match,omitempty"` DefaultOperator string `json:"default_operator,omitempty"` Analyzer string `json:"analyzer,omitempty"` Lenient bool `json:"lenient,omitempty"` Boost int64 `json:"boost,omitempty"` AllowLeadingWildcard bool `json:"allow_leading_wildcard,omitempty"` EnablePositionIncrements bool `json:"enable_position_increments,omitempty"` PhraseSlop int64 `json:"phrase_slop,omitempty"` MaxDeterminizedStates int64 `json:"max_determinized_states,omitempty"` TimeZone string `json:"time_zone,omitempty"` QuoteFieldSuffix string `json:"quote_field_suffix,omitempty"` QuoteAnalyzer string `json:"quote_analyzer,omitempty"` AnalyzeWildcard bool `json:"analyze_wildcard,omitempty"` AutoGenerateSynonymsPhraseQuery bool `json:"auto_generate_synonyms_phrase_query,omitempty"` }
type SearchRequest ¶
type SearchRequest struct { Version bool `json:"version,omitempty"` From int64 `json:"from,omitempty"` Size int64 `json:"size"` Sort []map[string]map[string]interface{} `json:"sort,omitempty"` StoredFields []string `json:"stored_fields,omitempty"` Source *Source `json:"_source,omitempty"` Query *Query `json:"query,omitempty"` Collapse *Collapse `json:"collapse,omitempty"` Aggs map[string]Aggs `json:"aggs,omitempty"` SearchAfter []int64 `json:"search_after,omitempty"` ScriptFields interface{} `json:"script_fields,omitempty"` }
func (SearchRequest) SearchIn ¶
func (q SearchRequest) SearchIn(ctx context.Context, index []string) (SearchResult, error)
type SearchResult ¶
type SerialDiff ¶
type SerialDiff struct { Lag int `json:"lag,omitempty"` PipelineAgg }
type SimpleQueryString ¶
type SimpleQueryString struct { Query string `json:"query,omitempty"` Fields []string `json:"fields,omitempty"` Flags string `json:"flags,omitempty"` FuzzyTranspositions bool `json:"fuzzy_transpositions,omitempty"` FuzzyMaxExpansions int64 `json:"fuzzy_max_expansions,omitempty"` FuzzyPrefixLength int64 `json:"fuzzy_prefix_length,omitempty"` MinimumShouldMatch int64 `json:"minimum_should_match,omitempty"` DefaultOperator string `json:"default_operator,omitempty"` Analyzer string `json:"analyzer,omitempty"` Lenient bool `json:"lenient,omitempty"` QuoteFieldSuffix string `json:"quote_field_suffix,omitempty"` AnalyzeWildcard bool `json:"analyze_wildcard,omitempty"` AutoGenerateSynonymsPhraseQuery bool `json:"auto_generate_synonyms_phrase_query,omitempty"` }