opensearch

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventSubstr    string = "events"
	AlertSubstr    string = "alerts"
	RelationSubstr string = "relations"
)

Variables

This section is empty.

Functions

func BuildCurrentIndex

func BuildCurrentIndex(tenant uuid.UUID, elements ...string) string

BuildCurrentIndex returns a string representing the current index based on the given elements.

func BuildIndex

func BuildIndex(tenant uuid.UUID, date time.Time, elements ...string) string

BuildIndex returns a string representing an index based on the given date and elements.

func BuildIndexPattern

func BuildIndexPattern(tenant uuid.UUID, elements ...string) string

BuildIndexPattern returns a string representing an index pattern based on the given elements.

func Bulk added in v0.11.15

func Bulk(ctx context.Context, items []BulkItem) error

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 Connect

func Connect(nodes []string) error

func IndexDoc

func IndexDoc(ctx context.Context, doc interface{}, index, id string) error

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 Agg

type Agg struct {
	Field string `json:"field,omitempty"`
	Size  int64  `json:"size,omitempty"`
}

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 Bool

type Bool struct {
	Must               []Query     `json:"must,omitempty"`
	Filter             []Query     `json:"filter,omitempty"`
	Should             []Query     `json:"should,omitempty"`
	MustNot            []Query     `json:"must_not,omitempty"`
	MinimumShouldMatch interface{} `json:"minimum_should_match,omitempty"`
}

type BulkItem added in v0.11.15

type BulkItem struct {
	Index  string
	Id     string
	Body   []byte
	Action string
}

type Cardinality

type Cardinality struct {
	Field              string `json:"field,omitempty"`
	PrecisionThreshold int64  `json:"precision_threshold,omitempty"`
}

type Collapse

type Collapse struct {
	Field string `json:"field,omitempty"`
}

type DateRange

type DateRange struct {
	Format string `json:"format,omitempty"`
	Range
}

type ExtendedStats

type ExtendedStats struct {
	Field string `json:"field,omitempty"`
	Sigma int64  `json:"sigma,omitempty"`
}

type GeoDistance

type GeoDistance struct {
	Origin interface{} `json:"origin,omitempty"`
	Range
}

type Grid

type Grid struct {
	Field     string      `json:"field,omitempty"`
	Precision int         `json:"precision,omitempty"`
	Bounds    interface{} `json:"bounds,omitempty"`
	Size      int         `json:"size,omitempty"`
	ShardSize int         `json:"shard_size,omitempty"`
}
type Header struct {
	Index *string `json:"_index,omitempty"`
	Id    *string `json:"_id,omitempty"`
}

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"`
}

func (Hit) Delete

func (h Hit) Delete(ctx context.Context) error

Delete deletes the document from the OpenSearch index.

func (Hit) Save

func (h Hit) Save(ctx context.Context) error

Save updates the document in the index.

type HitSource

type HitSource map[string]interface{}

func (HitSource) ParseSource

func (h HitSource) ParseSource(dest interface{}) error

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.

func (*HitSource) SetSource

func (h *HitSource) SetSource(src interface{}) error

SetSource sets the HitSource object from the provided source object.

type Hits

type Hits struct {
	Total    Total       `json:"total"`
	MaxScore interface{} `json:"max_score"`
	Hits     []Hit       `json:"hits"`
}

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 MatchPhrase struct {
	Query          string `json:"query,omitempty"`
	Slop           int64  `json:"slop,omitempty"`
	Analyzer       string `json:"analyzer,omitempty"`
	ZeroTermsQuery string `json:"zero_terms_query,omitempty"`
}

type MatchPhrasePrefix

type MatchPhrasePrefix struct {
	Query         string `json:"query,omitempty"`
	Analyzer      string `json:"analyzer,omitempty"`
	MaxExpansions int64  `json:"max_expansions,omitempty"`
	Slop          int64  `json:"slop,omitempty"`
}

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 MultiTerms struct {
	Terms []Agg             `json:"terms,omitempty"`
	Order map[string]string `json:"order,omitempty"`
}

type PercentileRanks

type PercentileRanks struct {
	Field  string  `json:"field,omitempty"`
	Values []int64 `json:"values,omitempty"`
}

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 Range

type Range struct {
	Field  string                   `json:"field,omitempty"`
	Ranges []map[string]interface{} `json:"ranges,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 SearchResult struct {
	Took         int64                  `json:"took"`
	TimedOut     bool                   `json:"timed_out"`
	Shards       Shards                 `json:"_shards"`
	Hits         Hits                   `json:"hits"`
	Aggregations map[string]interface{} `json:"aggregations"`
}

type SerialDiff

type SerialDiff struct {
	Lag int `json:"lag,omitempty"`
	PipelineAgg
}

type Shards

type Shards struct {
	Total      int64 `json:"total"`
	Successful int64 `json:"successful"`
	Skipped    int64 `json:"skipped"`
	Failed     int64 `json:"failed"`
}

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"`
}

type Source

type Source struct {
	Includes []string `json:"includes,omitempty"`
	Excludes []string `json:"excludes,omitempty"`
}

type Terms

type Terms struct {
	Field       string `json:"field,omitempty"`
	Size        int64  `json:"size,omitempty"`
	Missing     string `json:"missing,omitempty"`
	MinDocCount int64  `json:"min_doc_count,omitempty"`
}

type TopHits

type TopHits struct {
	Size int64 `json:"size,omitempty"`
}

type Total

type Total struct {
	Value    int64  `json:"value"`
	Relation string `json:"relation"`
}

type Update

type Update struct {
	Doc map[string]interface{} `json:"doc"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL