Documentation
¶
Index ¶
- Constants
- func ConvertSubAggregations(bucketAgg BucketAggregation, converter AggregateVersionConverter) (map[string]Aggregation, error)
- func ReadAggregationResult[A any, P PtrTo[A], R AggregationResultSet](name string, aggResponse R, subAggResponse P) (error, bool)
- func ReadDocument[D any, P PtrTo[D], R DocumentResult](docResult R, document P) error
- type ActionError
- type ActionResponse
- type AggregateVersionConverter
- type Aggregation
- type AggregationResultSet
- type BoolQuery
- func (q *BoolQuery) Filter(queries ...Query) *BoolQuery
- func (q *BoolQuery) MinimumShouldMatch(n int) *BoolQuery
- func (q *BoolQuery) Must(queries ...Query) *BoolQuery
- func (q *BoolQuery) MustNot(queries ...Query) *BoolQuery
- func (q *BoolQuery) Should(queries ...Query) *BoolQuery
- func (q *BoolQuery) ToOpenSearchJSON() ([]byte, error)
- type BucketAggregation
- type BucketSortAggregation
- func (b *BucketSortAggregation) AddSort(field string, isDesc bool) *BucketSortAggregation
- func (b *BucketSortAggregation) ToOpenSearchJSON() ([]byte, error)
- func (b *BucketSortAggregation) Validate() ValidationResults
- func (b *BucketSortAggregation) WithFrom(from int) *BucketSortAggregation
- func (b *BucketSortAggregation) WithSize(size int) *BucketSortAggregation
- type Bulk
- type BulkAction
- type BulkActionType
- type BulkRequest
- type BulkResponse
- type DateHistogramAggregation
- func (d *DateHistogramAggregation) AddOrder(orders ...Order) *DateHistogramAggregation
- func (d *DateHistogramAggregation) AddSubAggregation(name string, agg Aggregation) BucketAggregation
- func (d *DateHistogramAggregation) SubAggregations() map[string]Aggregation
- func (d *DateHistogramAggregation) ToOpenSearchJSON() ([]byte, error)
- func (d *DateHistogramAggregation) Validate() ValidationResults
- func (d *DateHistogramAggregation) WithMinDocCount(minCount int64) *DateHistogramAggregation
- func (d *DateHistogramAggregation) WithTimeZone(tz string) *DateHistogramAggregation
- type DateHistogramAggregationResults
- type DateHistogramBucketResult
- type DateRangeAggregation
- func (dr *DateRangeAggregation) AddKeyedRange(key string, from, to any) *DateRangeAggregation
- func (dr *DateRangeAggregation) AddRange(from, to any) *DateRangeAggregation
- func (dr *DateRangeAggregation) AddRanges(ranges ...Range) *DateRangeAggregation
- func (dr *DateRangeAggregation) AddSubAggregation(name string, agg Aggregation) BucketAggregation
- func (dr *DateRangeAggregation) SubAggregations() map[string]Aggregation
- func (dr *DateRangeAggregation) ToOpenSearchJSON() ([]byte, error)
- func (dr *DateRangeAggregation) Validate() ValidationResults
- func (dr *DateRangeAggregation) WithFormat(format string) *DateRangeAggregation
- type DateRangeAggregationResults
- type DocumentRef
- type DocumentResult
- type Error
- type ExistsQuery
- type FilterAggregation
- type FilterAggregationResults
- type Hit
- type Hits
- type MGet
- type MGetRequest
- type MGetResponse
- type MGetResult
- type MatchAllQuery
- type MatchPhraseQuery
- type MatchQuery
- type NestedQuery
- type OpenSearchResponse
- type Order
- type PercentilesAggregation
- type PercentilesAggregationResult
- type PrefixQuery
- type PtrTo
- type Query
- type QueryVersionConverter
- type Range
- type RangeAggregation
- func (r *RangeAggregation) AddKeyedRange(key string, from, to any) *RangeAggregation
- func (r *RangeAggregation) AddRange(from, to any) *RangeAggregation
- func (r *RangeAggregation) AddRanges(ranges ...Range) *RangeAggregation
- func (r *RangeAggregation) AddSubAggregation(name string, agg Aggregation) BucketAggregation
- func (r *RangeAggregation) SubAggregations() map[string]Aggregation
- func (r *RangeAggregation) ToOpenSearchJSON() ([]byte, error)
- func (r *RangeAggregation) Validate() ValidationResults
- type RangeAggregationResults
- type RangeBucketResult
- type RangeQuery
- type Refresh
- type RegexQuery
- type RoutableDoc
- type Search
- type SearchRequest
- func (r *SearchRequest) AddAggregation(name string, agg Aggregation) *SearchRequest
- func (r *SearchRequest) AddIndices(indices ...string) *SearchRequest
- func (r *SearchRequest) AddSorts(sort ...Sort) *SearchRequest
- func (r *SearchRequest) WithFrom(n int) *SearchRequest
- func (r *SearchRequest) WithQuery(q Query) *SearchRequest
- func (r *SearchRequest) WithRouting(routing ...string) *SearchRequest
- func (r *SearchRequest) WithSize(n int) *SearchRequest
- func (r *SearchRequest) WithTrackTotalHits(track any) *SearchRequest
- type SearchResponse
- type ShardMeta
- type SingleValueAggType
- type SingleValueAggregationResult
- type SingleValueMetricAggregation
- func NewAverageAggregation(field string) *SingleValueMetricAggregation
- func NewCardinalityAggregation(field string) *SingleValueMetricAggregation
- func NewMaximumAggregation(field string) *SingleValueMetricAggregation
- func NewMinimumAggregation(field string) *SingleValueMetricAggregation
- func NewSumAggregation(field string) *SingleValueMetricAggregation
- func (s *SingleValueMetricAggregation) ToOpenSearchJSON() ([]byte, error)
- func (s *SingleValueMetricAggregation) Validate() ValidationResults
- func (s *SingleValueMetricAggregation) WithMissing(missing any) *SingleValueMetricAggregation
- func (s *SingleValueMetricAggregation) WithPrecisionThreshold(p int) *SingleValueMetricAggregation
- type Sort
- type TermBucketResult
- type TermQuery
- type TermsAggregation
- func (t *TermsAggregation) AddOrder(orders ...Order) *TermsAggregation
- func (t *TermsAggregation) AddSubAggregation(name string, agg Aggregation) BucketAggregation
- func (t *TermsAggregation) SubAggregations() map[string]Aggregation
- func (t *TermsAggregation) ToOpenSearchJSON() ([]byte, error)
- func (t *TermsAggregation) Validate() ValidationResults
- func (t *TermsAggregation) WithExclude(exclude string) *TermsAggregation
- func (t *TermsAggregation) WithExcludes(excludes []string) *TermsAggregation
- func (t *TermsAggregation) WithInclude(include string) *TermsAggregation
- func (t *TermsAggregation) WithIncludes(include []string) *TermsAggregation
- func (t *TermsAggregation) WithMinDocCount(minCount int64) *TermsAggregation
- func (t *TermsAggregation) WithMissing(missing string) *TermsAggregation
- func (t *TermsAggregation) WithSize(size int) *TermsAggregation
- type TermsAggregationResults
- type TermsQuery
- type Total
- type ValidationError
- type ValidationResult
- type ValidationResults
- type Validator
- type WildcardQuery
Constants ¶
const ( CardinalityAggregation = SingleValueAggType("cardinality") MaximumAggregation = SingleValueAggType("max") MinimumAggregation = SingleValueAggType("min") AverageAggregation = SingleValueAggType("avg") SumAggregation = SingleValueAggType("sum") )
Variables ¶
This section is empty.
Functions ¶
func ConvertSubAggregations ¶
func ConvertSubAggregations(bucketAgg BucketAggregation, converter AggregateVersionConverter) (map[string]Aggregation, error)
ConvertSubAggregations executes the AggregationVersionConverter against all sub aggregations for a BucketAggregation
func ReadAggregationResult ¶
func ReadAggregationResult[A any, P PtrTo[A], R AggregationResultSet](name string, aggResponse R, subAggResponse P) (error, bool)
ReadAggregationResult generically reads a sub bucket from a AggregationResultSet and parses it into the passed aggregation response. It returns an exists boolean, if the agg key is in the result set, and an error if it failed to be read. subAggResponse can be any pointer type.
func ReadDocument ¶
func ReadDocument[D any, P PtrTo[D], R DocumentResult](docResult R, document P) error
ReadDocument reads the source from a DocumentResult and parses it into the passed document object. Document can be any pointer type.
Types ¶
type ActionError ¶
type ActionError struct { Type string `json:"type"` Reason string `json:"reason"` Index string `json:"index"` Shard string `json:"shard"` IndexUUID string `json:"index_uuid"` }
ActionError encapsulates error responses from OpenSearch on bulk Actions
type ActionResponse ¶
type ActionResponse struct { Type string `json:"-"` Index string `json:"_index"` ID string `json:"_id"` Version uint64 `json:"_version"` Result string `json:"result"` Shards *ShardMeta `json:"_shards,omitempty"` SeqNo uint64 `json:"_seq_no"` PrimaryTerm uint64 `json:"_primary_term"` Status int `json:"status"` Error *ActionError `json:"error"` }
ActionResponse is a domain model union type for all the fields of action responses for all supported OpenSearch versions. Currently supported versions are:
- OpenSearch 2
func (*ActionResponse) UnmarshalJSON ¶
func (o *ActionResponse) UnmarshalJSON(m []byte) error
UnmarshalJSON implements json.Unmarshaler to decode a json byte slice into an ActionResponse
type AggregateVersionConverter ¶
type AggregateVersionConverter func(Aggregation) (Aggregation, error)
AggregateVersionConverter takes in a domain model Aggregation and makes any modifications or conversions needed for a specific version of OpenSearch.
type Aggregation ¶
type Aggregation interface { // ToOpenSearchJSON converts the Aggregation struct to the expected OpenSearch JSON ToOpenSearchJSON() ([]byte, error) // Validate that the aggregation is executable Validate() ValidationResults }
Aggregation wraps all aggregation types into a common interface. Facilitating adding aggregations to opensearchtools.SearchRequests and marshaling into OpenSearch JSON.
type AggregationResultSet ¶
type AggregationResultSet interface { // GetAggregationResultSource fetches the raw JSON source for the provided name. // Returns nil, false if no aggregation response with the name exists. GetAggregationResultSource(name string) ([]byte, bool) // Keys returns a slice of keys for the list of sub aggregation results Keys() []string }
AggregationResultSet represents a collection of Aggregation responses. This result set exists in two places:
- SearchResponse for a SearchRequest that included aggregations
- [BucketAggregation]s that have added sub aggregations to include.
The result set is characterized by the ability to contain multiple results keyed by the aggregation name.
type BoolQuery ¶
type BoolQuery struct {
// contains filtered or unexported fields
}
BoolQuery combines other queries to form more complex statements. An empty BoolQuery is executable by OpenSearch. Without any constraints it will match on everything.
For more details see https://opensearch.org/docs/latest/opensearch/query-dsl/bool/
func NewBoolQuery ¶
func NewBoolQuery() *BoolQuery
NewBoolQuery instantiates an empty boolean query.
func (*BoolQuery) Filter ¶
Filter Logical AND operator that is applied first to reduce your dataset before applying the queries. A query within a filter clause is a yes or no option. If a document matches the query, it is returned in the results; otherwise, it is not. The results of a filter query are generally cached to allow for a faster return. Use the filter query to filter the results based on exact matches, ranges, dates, numbers, and so on.
func (*BoolQuery) MinimumShouldMatch ¶
MinimumShouldMatch Optional parameter for use with a should query clause. Specifies the minimum number of queries that the document must match for it to be returned in the results.
func (*BoolQuery) Must ¶
Must Logical AND operator. The results must match the queries in this clause. If you have multiple queries, all of them must match.
func (*BoolQuery) MustNot ¶
MustNot Logical NOT operator. All matches are excluded from the results.
func (*BoolQuery) Should ¶
Should Logical OR operator. The results must match at least one of the queries, but, optionally, they can match more than one query. Each matching should clause increases the relevancy score. You can set the minimum number of queries that must match using BoolQuery.MinimumShouldMatch
func (*BoolQuery) ToOpenSearchJSON ¶
ToOpenSearchJSON coverts the BoolQuery to the correct OpenSearch JSON
type BucketAggregation ¶
type BucketAggregation interface { Aggregation // AddSubAggregation to the BucketAggregation for further refinement. AddSubAggregation(name string, agg Aggregation) BucketAggregation // SubAggregations returns all aggregations added to the BucketAggregation SubAggregations() map[string]Aggregation }
BucketAggregation represents a family of OpenSearch aggregations. Bucket aggregations categorize sets of documents as buckets. The type of bucket aggregation determines whether a given document falls into a bucket or not. Bucket aggregations also support adding nested aggregations to further refine bucket results.
For more details, see https://opensearch.org/docs/latest/opensearch/bucket-agg/
type BucketSortAggregation ¶
type BucketSortAggregation struct { // From - the number of buckets to be truncated before returning // Negative values will be omitted From int // Size - the number of buckets to be returned // Negative values will be omitted Size int // Sort for the parent aggregation Sort []sort }
BucketSortAggregation is a [pipeline aggregation] that modifies its parent aggregation by sorting and truncating the results. It does not generate a response itself. An empty BucketSortAggregation will return no results due to the default size of 0.
For more details see https://opensearch.org/docs/latest/opensearch/pipeline-agg/#bucket_sort [pipeline aggregation]: https://opensearch.org/docs/latest/opensearch/pipeline-agg/
func NewBucketSortAggregation ¶
func NewBucketSortAggregation() *BucketSortAggregation
NewBucketSortAggregation instantiates a BucketSortAggregation with From and Size set to -1 to be omitted in favor of OpenSearch defaults
func (*BucketSortAggregation) AddSort ¶
func (b *BucketSortAggregation) AddSort(field string, isDesc bool) *BucketSortAggregation
AddSort for the targeted field
func (*BucketSortAggregation) ToOpenSearchJSON ¶
func (b *BucketSortAggregation) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the BucketSortAggregation struct to the expected OpenSearch JSON. Implements [Aggregation.ToOpenSearchJSON].
func (*BucketSortAggregation) Validate ¶
func (b *BucketSortAggregation) Validate() ValidationResults
Validate that the aggregation is executable. Implements [Aggregation.Validate].
func (*BucketSortAggregation) WithFrom ¶
func (b *BucketSortAggregation) WithFrom(from int) *BucketSortAggregation
WithFrom for the number of buckets to be truncated before returning
func (*BucketSortAggregation) WithSize ¶
func (b *BucketSortAggregation) WithSize(size int) *BucketSortAggregation
WithSize for the number of buckets to be returned
type Bulk ¶
type Bulk interface {
Bulk(ctx context.Context, req *BulkRequest) (OpenSearchResponse[BulkResponse], error)
}
Bulk defines a method which knows how to make an OpenSearch Bulk request. It should be implemented by a version-specific executor.
type BulkAction ¶
type BulkAction struct { Type BulkActionType Doc RoutableDoc }
BulkAction is a domain model union type for all actions a BulkRequest can perform across all supported OpenSearch versions. Currently supported versions are:
- OpenSearch 2
While the struct has all the combined fields, only valid fields will be marshaled depending on the type of action. For this reason, it's recommended to use the type constructors:
- NewIndexBulkAction
- NewCreateBulkAction
- NewDeleteBulkAction
- NewUpdateBulkAction
For more details, see https://opensearch.org/docs/latest/api-reference/document-apis/bulk/#request-body
func NewCreateBulkAction ¶
func NewCreateBulkAction(doc RoutableDoc) BulkAction
NewCreateBulkAction instantiates a BulkCreate action.
func NewDeleteBulkAction ¶
func NewDeleteBulkAction(index, id string) BulkAction
NewDeleteBulkAction instantiates a BulkDelete action.
func NewIndexBulkAction ¶
func NewIndexBulkAction(doc RoutableDoc) BulkAction
NewIndexBulkAction instantiates a BulkIndex action.
func NewUpdateBulkAction ¶
func NewUpdateBulkAction(doc RoutableDoc) BulkAction
NewUpdateBulkAction instantiates a BulkUpdate action.
func (*BulkAction) MarshalJSONLines ¶
func (b *BulkAction) MarshalJSONLines() ([][]byte, error)
MarshalJSONLines marshals the BulkAction into the appropriate JSON lines depending on the BulkActionType.
type BulkActionType ¶
type BulkActionType string
BulkActionType is an enum for the various BulkActionTypes.
const ( // BulkCreate creates a document if it doesn’t already exist and returns an error otherwise. BulkCreate BulkActionType = "create" // BulkIndex creates a document if it doesn’t yet exist and replaces the document if it already exists. BulkIndex BulkActionType = "index" // BulkDelete deletes a document if it exists. If the document doesn’t exist, // OpenSearch doesn’t return an error, but instead returns not_found under ActionResponse.Result. BulkDelete BulkActionType = "delete" // BulkUpdate updates existing documents and returns an error if the document doesn’t exist. BulkUpdate BulkActionType = "update" )
type BulkRequest ¶
type BulkRequest struct { // Actions lists the actions to be performed in the BulkRequest Actions []BulkAction // Refresh determines if the request should wait for a refresh or not Refresh Refresh // Index determines the entire index for the request Index string // ParseResponseItemsOnlyOnFailure determines if the bulk response is parsed all the time or only when errors present in the response ParseResponseItemsOnlyOnFailure bool }
BulkRequest is a domain model union type for all the fields of BulkRequests for all supported OpenSearch versions. Currently supported versions are:
- OpenSearch 2
An empty BulkRequest will fail to execute. At least one Action is required to be added.
func NewBulkRequest ¶
func NewBulkRequest() *BulkRequest
NewBulkRequest instantiates an empty BulkRequest
func (*BulkRequest) Add ¶
func (r *BulkRequest) Add(actions ...BulkAction) *BulkRequest
Add an action to the BulkRequest.
func (*BulkRequest) WithIndex ¶
func (r *BulkRequest) WithIndex(index string) *BulkRequest
WithIndex on the request
type BulkResponse ¶
type BulkResponse struct { Took int64 Errors bool Items []ActionResponse Error *Error }
BulkResponse is a domain model union response type for BulkRequest for all supported OpenSearch versions. Currently supported versions are:
- OpenSearch 2
Contains a slice of ActionResponse for each individual BulkAction performed by the request.
type DateHistogramAggregation ¶
type DateHistogramAggregation struct { // Field to be bucketed Field string // MinDocCount is the lower count threshold for a bucket to be included in the results. // Negative counts will be omitted MinDocCount int64 // Interval string using OpenSearch [date math]. // [date math]: https://opensearch.org/docs/latest/opensearch/supported-field-types/date/#date-math Interval string // TimeZone, times are stored internally in UTC and by default date histograms are bucketed in UTC. // Set the TimeZone to overwrite this default TimeZone string // Order list of [Order]s to sort the aggregation buckets. Default order is _count: desc Order []Order // Aggregations sub aggregations for each bucket. Mapped by string label to sub aggregation Aggregations map[string]Aggregation }
DateHistogramAggregation buckets documents based on a date interval. An empty DateHistogramAggregation will have several issues with execution:
- the target Field must be non-null and non-empty
- the Interval must be non-null and non-empty
For more details see https://opensearch.org/docs/latest/opensearch/bucket-agg/#histogram-date_histogram
func NewDateHistogramAggregation ¶
func NewDateHistogramAggregation(field, interval string) *DateHistogramAggregation
NewDateHistogramAggregation instantiates a DateHistogramAggregation targeting the provided field with the provided interval. Sets the MinDocCount to -1 to be omitted in favor of the OpenSearch default.
func (*DateHistogramAggregation) AddOrder ¶
func (d *DateHistogramAggregation) AddOrder(orders ...Order) *DateHistogramAggregation
AddOrder of the returned buckets
func (*DateHistogramAggregation) AddSubAggregation ¶
func (d *DateHistogramAggregation) AddSubAggregation(name string, agg Aggregation) BucketAggregation
AddSubAggregation to the TermsAggregation with the provided name Implements [BucketAggregation.AddSubAggregation]
func (*DateHistogramAggregation) SubAggregations ¶
func (d *DateHistogramAggregation) SubAggregations() map[string]Aggregation
SubAggregations returns all aggregations added to the bucket aggregation. Implements [BucketAggregation.SubAggregations]
func (*DateHistogramAggregation) ToOpenSearchJSON ¶
func (d *DateHistogramAggregation) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the TermsAggregation to the correct OpenSearch JSON. Implements [Aggregation.ToOpenSearchJSON].
func (*DateHistogramAggregation) Validate ¶
func (d *DateHistogramAggregation) Validate() ValidationResults
Validate that the aggregation is executable. Implements [Aggregation.Validate].
func (*DateHistogramAggregation) WithMinDocCount ¶
func (d *DateHistogramAggregation) WithMinDocCount(minCount int64) *DateHistogramAggregation
WithMinDocCount the lower count threshold for a bucket to be included in the results
func (*DateHistogramAggregation) WithTimeZone ¶
func (d *DateHistogramAggregation) WithTimeZone(tz string) *DateHistogramAggregation
WithTimeZone overwriting the default UTC timezone
type DateHistogramAggregationResults ¶
type DateHistogramAggregationResults struct {
Buckets []DateHistogramBucketResult
}
DateHistogramAggregationResults represents the results from a DateHistogramAggregation request
func (*DateHistogramAggregationResults) UnmarshalJSON ¶
func (d *DateHistogramAggregationResults) UnmarshalJSON(m []byte) error
UnmarshalJSON implements json.Unmarshaler to decode a json byte slice into a DateHistogramAggregationResults Errors on unknown fields.
type DateHistogramBucketResult ¶
type DateHistogramBucketResult struct { KeyString string Key int64 DocCount int64 SubAggregationResults map[string]json.RawMessage }
DateHistogramBucketResult is a [AggregationResultMap] for a DateHistogramAggregation
func (*DateHistogramBucketResult) GetAggregationResultSource ¶
func (d *DateHistogramBucketResult) GetAggregationResultSource(name string) ([]byte, bool)
GetAggregationResultSource implements opensearchtools.AggregationResultSet to fetch a sub aggregation result and return the raw JSON source for the provided name.
func (*DateHistogramBucketResult) Keys ¶
func (d *DateHistogramBucketResult) Keys() []string
Keys implemented for opensearchtools.AggregationResultSet to return the list of aggregation result keys
func (*DateHistogramBucketResult) UnmarshalJSON ¶
func (d *DateHistogramBucketResult) UnmarshalJSON(m []byte) error
UnmarshalJSON implements json.Unmarshaler to decode a json byte slice into a DateHistogramBucketResult
type DateRangeAggregation ¶
type DateRangeAggregation struct { // Field to be targeted Field string // Ranges - list of range buckets Ranges []Range // Format - the date format for the [RangeBucketResult.FromString] and // [RangeBucketResult.ToString] in the results Format string // Aggregations sub aggregations for each bucket. Mapped by string label to sub aggregation Aggregations map[string]Aggregation }
DateRangeAggregation is conceptually the same as the RangeAggregation, except that it lets you perform date math and format the date strings. An empty DateDateRangeAggregation will have some issues with execution
func NewDateRangeAggregation ¶
func NewDateRangeAggregation(field string) *DateRangeAggregation
NewDateRangeAggregation instantiates a DateRangeAggregation targeting the provided field.
func (*DateRangeAggregation) AddKeyedRange ¶
func (dr *DateRangeAggregation) AddKeyedRange(key string, from, to any) *DateRangeAggregation
AddKeyedRange adds a keyed range to the bucket list
func (*DateRangeAggregation) AddRange ¶
func (dr *DateRangeAggregation) AddRange(from, to any) *DateRangeAggregation
AddRange adds an un-keyed range to the bucket list
func (*DateRangeAggregation) AddRanges ¶
func (dr *DateRangeAggregation) AddRanges(ranges ...Range) *DateRangeAggregation
AddRanges adds any number of Ranges to the bucket list
func (*DateRangeAggregation) AddSubAggregation ¶
func (dr *DateRangeAggregation) AddSubAggregation(name string, agg Aggregation) BucketAggregation
AddSubAggregation to the DateRangeAggregation with the provided name Implements [BucketAggregation.AddSubAggregation]
func (*DateRangeAggregation) SubAggregations ¶
func (dr *DateRangeAggregation) SubAggregations() map[string]Aggregation
SubAggregations returns all aggregations added to the bucket aggregation. Implements [BucketAggregation.SubAggregations]
func (*DateRangeAggregation) ToOpenSearchJSON ¶
func (dr *DateRangeAggregation) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the DateRangeAggregation to the correct OpenSearch JSON. Implements [Aggregation.ToOpenSearchJSON].
func (*DateRangeAggregation) Validate ¶
func (dr *DateRangeAggregation) Validate() ValidationResults
Validate that the aggregation is executable. Implements [Aggregation.Validate].
func (*DateRangeAggregation) WithFormat ¶
func (dr *DateRangeAggregation) WithFormat(format string) *DateRangeAggregation
WithFormat for the date from and to response
type DateRangeAggregationResults ¶
type DateRangeAggregationResults struct {
Buckets []RangeBucketResult `json:"buckets"`
}
DateRangeAggregationResults represents the results from a range aggregation request.
type DocumentRef ¶
type DocumentRef struct {
// contains filtered or unexported fields
}
DocumentRef references a document via its index and id. It is the most basic implementation of RoutableDoc.
func NewDocumentRef ¶
func NewDocumentRef(index, id string) DocumentRef
NewDocumentRef constructs a DocumentRef with the core two identifiers, ID and Index.
func (DocumentRef) Index ¶
func (d DocumentRef) Index() string
Index returns the index the document should be routed to
type DocumentResult ¶
type DocumentResult interface { // GetSource returns the raw bytes of the document GetSource() []byte }
DocumentResult defines any OpenSearch response that contains a document source.
type Error ¶
type Error struct { RootCause []Error Type string Reason string Index string ResourceID string ResourceType string IndexUUID string }
Error encapsulates an error response from a given OpenSearch request.
type ExistsQuery ¶
type ExistsQuery struct {
// contains filtered or unexported fields
}
ExistsQuery searches for documents that contain a specific field.
For more details see https://opensearch.org/docs/latest/opensearch/query-dsl/term/#exists
func NewExistsQuery ¶
func NewExistsQuery(field string) *ExistsQuery
NewExistsQuery instantiates an exists query. An empty field value will be rejected by OpenSearch
func (*ExistsQuery) ToOpenSearchJSON ¶
func (q *ExistsQuery) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the ExistsQuery to the correct OpenSearch JSON.
type FilterAggregation ¶
type FilterAggregation struct { // Filter to be applied to the document set before aggregating Filter Query // Aggregations to be performed on the reduced set Aggregations map[string]Aggregation }
FilterAggregation is a query clause, exactly like a search query. You can use the FilterAggregation to narrow down the entire set of documents to a specific set before creating buckets. An empty FilterAggregation will fail to execute as a filter is required.
For more details see https://opensearch.org/docs/latest/opensearch/bucket-agg/#filter-filters
func NewFilterAggregation ¶
func NewFilterAggregation(filter Query) *FilterAggregation
NewFilterAggregation instantiates a FilterAggregation with the provided filter
func (*FilterAggregation) AddSubAggregation ¶
func (f *FilterAggregation) AddSubAggregation(name string, agg Aggregation) BucketAggregation
AddSubAggregation to the FilterAggregation with the provided name Implements [BucketAggregation.AddSubAggregation]
func (*FilterAggregation) SubAggregations ¶
func (f *FilterAggregation) SubAggregations() map[string]Aggregation
SubAggregations returns all aggregations added to the bucket aggregation. Implements [BucketAggregation.SubAggregations]
func (*FilterAggregation) ToOpenSearchJSON ¶
func (f *FilterAggregation) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the FilterAggregation to the correct OpenSearch JSON. Implements [Aggregation.ToOpenSearchJSON].
func (*FilterAggregation) Validate ¶
func (f *FilterAggregation) Validate() ValidationResults
Validate that the aggregation is executable. Implements [Aggregation.Validate].
type FilterAggregationResults ¶
type FilterAggregationResults struct { DocCount uint64 SubAggregationResults map[string]json.RawMessage }
FilterAggregationResults is a [AggregationResultMap] for a FilterAggregation
func (*FilterAggregationResults) GetAggregationResultSource ¶
func (f *FilterAggregationResults) GetAggregationResultSource(name string) ([]byte, bool)
GetAggregationResultSource implements opensearchtools.AggregationResultSet to fetch a sub aggregation result and return the raw JSON source for the provided name.
func (*FilterAggregationResults) Keys ¶
func (f *FilterAggregationResults) Keys() []string
Keys implemented for opensearchtools.AggregationResultSet to return the list of aggregation result keys
func (*FilterAggregationResults) UnmarshalJSON ¶
func (f *FilterAggregationResults) UnmarshalJSON(m []byte) error
UnmarshalJSON implements json.Unmarshaler to decode a json byte slice into a FilterAggregationResults. Unknown fields are assumed to be SubAggregation results
type Hit ¶
type Hit struct { Index string ID string Score float64 Source json.RawMessage }
Hit is a domain model union response type across all supported OpenSearch versions. Currently supported versions are:
-OpenSearch2
Hit the individual document found by the `[Query] performed by the SearchRequest.
type Hits ¶
type Hits struct { // Total documents that matched the query. Total Total // MaxScore max score of all matching documents MaxScore float64 // Hits slice of documents matched by the [Query] Hits []Hit }
Hits is a domain model union response type across all supported OpenSearch versions. Currently supported versions are:
-OpenSearch2
Hits are the list of documents hit from the executed Query.
type MGet ¶
type MGet interface {
MGet(ctx context.Context, req *MGetRequest) (OpenSearchResponse[MGetResponse], error)
}
MGet defines a method which knows how to make an OpenSearch Multi-get request. It should be implemented by a version-specific executor.
type MGetRequest ¶
type MGetRequest struct { // Index destination for entire request // if used individual documents don't need to specify the index Index string // Docs are the list of documents to be fetched. Docs []RoutableDoc }
MGetRequest is a domain model union type for all the fields of a Multi-Get request for all supported OpenSearch versions. Currently supported versions are:
- OpenSearch 2
This MGetRequest is intended to be used along with a version-specific executor such as opensearchtools/osv2.Executor. For example:
mgetReq := NewMGetRequest(). Add("example_index", "example_id") mgetResp, err := osv2Executor.MGet(ctx, mgetReq)
An error can be returned if
- The request to OpenSearch fails
- The results json cannot be unmarshalled
func NewMGetRequest ¶
func NewMGetRequest() *MGetRequest
NewMGetRequest instantiates an empty MGetRequest. An empty MGetRequest is executable but will return zero documents because zero have been requested.
func (*MGetRequest) Add ¶
func (m *MGetRequest) Add(index, id string) *MGetRequest
Add a DocumentRef to the documents being requested. If index is an empty string, the request relies on the top-level MGetRequest.Index.
func (*MGetRequest) AddDocs ¶
func (m *MGetRequest) AddDocs(docs ...RoutableDoc) *MGetRequest
AddDocs - add any number RoutableDoc to the documents being requested. If the doc does not return anything for [RoutableDoc.Index], the request relies on the top level [MGetRequest.Index].
func (*MGetRequest) WithIndex ¶
func (m *MGetRequest) WithIndex(index string) *MGetRequest
WithIndex sets the top level index for the request. If a individual document request does not have an index specified, this index will be used.
type MGetResponse ¶
type MGetResponse struct {
Docs []MGetResult
}
MGetResponse is a domain model union response type for Multi-Get for all supported OpenSearch versions. Currently supported versions are:
- OpenSearch 2
Contains a slice of MGetResult for each document in the response.
type MGetResult ¶
type MGetResult struct { Index string ID string Version int SeqNo int PrimaryTerm int Found bool Source json.RawMessage Error error }
MGetResult is a domain model union type representing an individual document result in for a request item in a Multi-Get response for all supported OpenSearch versions. Currently supported versions are:
- OpenSearch 2
func (MGetResult) GetSource ¶
func (m MGetResult) GetSource() []byte
GetSource returns the raw bytes of the document of the MGetResult.
type MatchAllQuery ¶
type MatchAllQuery struct { }
MatchAllQuery returns all documents.
For more details see https://opensearch.org/docs/latest/opensearch/query-dsl/full-text/#match-all
func NewMatchAllQuery ¶
func NewMatchAllQuery() *MatchAllQuery
NewMatchAllQuery instantiates a MatchAllQuery.
func (*MatchAllQuery) ToOpenSearchJSON ¶
func (q *MatchAllQuery) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the MatchAllQuery to the correct OpenSearch JSON.
type MatchPhraseQuery ¶
type MatchPhraseQuery struct {
// contains filtered or unexported fields
}
MatchPhraseQuery finds document that match documents that contain an exact phrase in a specified order. An empty MatchPhraseQuery will be rejected by OpenSearch for two reasons:
- a field must not be empty or null
- a value must be non-null
For more details see https://opensearch.org/docs/latest/opensearch/query-dsl/full-text/#match-phrase
func NewMatchPhraseQuery ¶
func NewMatchPhraseQuery(field, phrase string) *MatchPhraseQuery
NewMatchPhraseQuery instantiates a MatchPhraseQuery targeting field and looking for phrase.
func (*MatchPhraseQuery) ToOpenSearchJSON ¶
func (q *MatchPhraseQuery) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the MatchPhraseQuery to the correct OpenSearch JSON.
type MatchQuery ¶
type MatchQuery struct {
// contains filtered or unexported fields
}
MatchQuery finds documents that matches the analyzed string value.
For more details see https://opensearch.org/docs/latest/opensearch/query-dsl/full-text/#match
func NewMatchQuery ¶
func NewMatchQuery(field, value string) *MatchQuery
NewMatchQuery initializes a MatchQuery targeting field and trying to match value.
func (*MatchQuery) SetOperator ¶
func (q *MatchQuery) SetOperator(op string) *MatchQuery
SetOperator sets the operator to use when using a boolean query. Can be "AND" or "OR" (default).
func (*MatchQuery) ToOpenSearchJSON ¶
func (q *MatchQuery) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the MatchQuery to the correct OpenSearch JSON.
type NestedQuery ¶ added in v0.4.0
type NestedQuery struct {
// contains filtered or unexported fields
}
NestedQuery is a type of joining query that allows searches in fields that are of the `nested` type. An empty NestedQuery will be rejected by OpenSearch for two reasons:
- a path must not be nil or empty
- a query must not be nil
For more details see https://opensearch.org/docs/latest/query-dsl/
func NewNestedQuery ¶ added in v0.4.0
func NewNestedQuery(path string, query Query) *NestedQuery
NewNestedQuery initializes a NestedQuery targeting the nested field at the given path, with the provided query.
func (*NestedQuery) ToOpenSearchJSON ¶ added in v0.4.0
func (q *NestedQuery) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the Nested to the correct OpenSearch JSON.
type OpenSearchResponse ¶
type OpenSearchResponse[T any] struct { ValidationResults ValidationResults StatusCode int Header http.Header Response T }
OpenSearchResponse is a generic return type for an OpenSearch query which has meta fields common to all response types as well as a generic Response field abstract across all response types.
func NewOpenSearchResponse ¶
func NewOpenSearchResponse[T any](vrs ValidationResults, statusCode int, header http.Header, response T) OpenSearchResponse[T]
Craete a new OpenSearchResponse instance with the given ValidationResults, status code, headers, and response.
type Order ¶
Order encapsulates the sorting capabilities for Aggregation requests to OpenSearch. An empty Order will be rejected by OpenSearch as the target must be non-nil and non-empty
func NewOrder ¶
NewOrder instantiates an aggregation Order with the target and whether it should be descending or ascending.
func (Order) ToOpenSearchJSON ¶
ToOpenSearchJSON converts the Order to the correct OpenSearch JSON.
type PercentilesAggregation ¶
type PercentilesAggregation struct { // Field to be bucketed Field string }
PercentilesAggregation is the percentage of the data that’s at or below a certain threshold value. An empty PercentilesAggregation will have some issues with execution:
- the target Field must be non-nil and non-empty.
For more details see https://opensearch.org/docs/latest/opensearch/metric-agg/#percentile-percentile_ranks
func NewPercentileAggregation ¶
func NewPercentileAggregation(field string) *PercentilesAggregation
NewPercentileAggregation instantiates a PercentilesAggregation tergeting the provided field.
func (*PercentilesAggregation) ToOpenSearchJSON ¶
func (p *PercentilesAggregation) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the PercentilesAggregation to the correct OpenSearch JSON. Implements [Aggregation.ToOpenSearchJSON].
func (*PercentilesAggregation) Validate ¶
func (p *PercentilesAggregation) Validate() ValidationResults
Validate that the aggregation is executable. Implements [Aggregation.Validate].
type PercentilesAggregationResult ¶ added in v0.2.0
type PercentilesAggregationResult struct { P1 *float64 P1String string P5 *float64 P5String string P25 *float64 P25String string P50 *float64 P50String string P75 *float64 P75String string P95 *float64 P95String string P99 *float64 P99String string }
PercentilesAggregationResult will contain all percentiles or no percentiles. If there are no values for the percentile, it will be omitted
func (*PercentilesAggregationResult) UnmarshalJSON ¶ added in v0.2.0
func (p *PercentilesAggregationResult) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler to decode a json byte slice into a PercentilesAggregationResult
type PrefixQuery ¶
type PrefixQuery struct {
// contains filtered or unexported fields
}
PrefixQuery finds documents that contain the value as a prefix. An empty PrefixQuery will be rejected by OpenSearch for two reasons:
- a field must not be empty or null
- a value must be non-null
For more details see https://opensearch.org/docs/latest/opensearch/query-dsl/term/#prefix
func NewPrefixQuery ¶
func NewPrefixQuery(field string, value any) *PrefixQuery
NewPrefixQuery initializes a PrefixQuery targeting field looking for the prefix of value.
func (*PrefixQuery) ToOpenSearchJSON ¶
func (q *PrefixQuery) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the PrefixQuery Source converts the MatchPhraseQuery to the correct OpenSearch JSON.
type PtrTo ¶
type PtrTo[T any] interface { *T }
PtrTo is a generic constraint that restricts value to be pointers. T can be any type.
type Query ¶
type Query interface { // ToOpenSearchJSON converts the Query struct to the expected OpenSearch JSON ToOpenSearchJSON() ([]byte, error) }
Query wraps all query types in a common interface. Facilitating a common pattern to convert the logical struct into the appropriate request JSON.
func BoolQueryConverter ¶
func BoolQueryConverter(boolQuery *BoolQuery, converter QueryVersionConverter) (Query, error)
BoolQueryConverter is a utility support QueryVersionConverter to iterate over all the nested queries in a BoolQuery
type QueryVersionConverter ¶
QueryVersionConverter takes in a domain model Query and makes any modifications or conversions needed for a specific version of OpenSearch
type Range ¶
type Range struct { // Key label for the range bucket. If one is not provided // OpenSearch defaults to "{From}-{To} Key string `json:"key,omitempty"` // From - lower inclusive bound of the range From any `json:"from,omitempty"` // To - upper exclusive bound of the range To any `json:"to,omitempty"` }
type RangeAggregation ¶
type RangeAggregation struct { // Field to be targeted Field string // Ranges - list of range buckets Ranges []Range // Aggregations sub aggregations for each bucket. Mapped by string label to sub aggregation Aggregations map[string]Aggregation }
RangeAggregation lets you manually define each bucket, and it's range. An empty RangeAggregation will have some issues with execution:
- the target Field must be non-nil and non-empty
- the aggregation must have at least one Range defined
For more details see https://opensearch.org/docs/latest/opensearch/bucket-agg/#range-date_range-ip_range
func NewRangeAggregation ¶
func NewRangeAggregation(field string) *RangeAggregation
NewRangeAggregation instantiates a RangeAggregation targeting the provided field.
func (*RangeAggregation) AddKeyedRange ¶
func (r *RangeAggregation) AddKeyedRange(key string, from, to any) *RangeAggregation
AddKeyedRange adds a keyed range to the bucket list
func (*RangeAggregation) AddRange ¶
func (r *RangeAggregation) AddRange(from, to any) *RangeAggregation
AddRange adds an un-keyed range to the bucket list
func (*RangeAggregation) AddRanges ¶
func (r *RangeAggregation) AddRanges(ranges ...Range) *RangeAggregation
AddRanges adds any number of Ranges to the bucket list
func (*RangeAggregation) AddSubAggregation ¶
func (r *RangeAggregation) AddSubAggregation(name string, agg Aggregation) BucketAggregation
AddSubAggregation to the RangeAggregation with the provided name Implements [BucketAggregation.AddSubAggregation]
func (*RangeAggregation) SubAggregations ¶
func (r *RangeAggregation) SubAggregations() map[string]Aggregation
SubAggregations returns all aggregations added to the bucket aggregation. Implements [BucketAggregation.SubAggregations]
func (*RangeAggregation) ToOpenSearchJSON ¶
func (r *RangeAggregation) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the RangeAggregation to the correct OpenSearch JSON. Implements [Aggregation.ToOpenSearchJSON].
func (*RangeAggregation) Validate ¶
func (r *RangeAggregation) Validate() ValidationResults
Validate that the aggregation is executable. Implements [Aggregation.Validate].
type RangeAggregationResults ¶
type RangeAggregationResults struct {
Buckets []RangeBucketResult `json:"buckets"`
}
RangeAggregationResults represents the results from a range aggregation request.
type RangeBucketResult ¶
type RangeBucketResult struct { // Key - the bucket label Key string // From - the lower inclusive bound of the bucket. // It will match the type of the [Range.From] in the request. From any // FromString - if the [Range.From] was not a string, // a string representation will also be included FromString string // To - the upper exclusive bound of the bucket. // It will match the type of the [Range.To] in the request. To any // ToString - if the [Range.To] was not a string, // a string representation will also be included ToString string // DocCount - number of documents that fit in this bucket DocCount int64 // SubAggregationResults for any nested aggregations SubAggregationResults map[string]json.RawMessage }
RangeBucketResult is a [AggregationResultMap] for a RangeAggregation
func (*RangeBucketResult) GetAggregationResultSource ¶
func (r *RangeBucketResult) GetAggregationResultSource(name string) ([]byte, bool)
GetAggregationResultSource implements opensearchtools.AggregationResultSet to fetch a sub aggregation result and return the raw JSON source for the provided name.
func (*RangeBucketResult) Keys ¶
func (r *RangeBucketResult) Keys() []string
Keys implemented for opensearchtools.AggregationResultSet to return the list of aggregation result keys
func (*RangeBucketResult) UnmarshalJSON ¶
func (r *RangeBucketResult) UnmarshalJSON(m []byte) error
UnmarshalJSON implements json.Unmarshaler to decode a json byte slice into a RangeBucketResult
type RangeQuery ¶
type RangeQuery struct {
// contains filtered or unexported fields
}
RangeQuery allows you to search on a targeted field matching a defined range. An empty RangeQuery will be rejected by OpenSearch as it requires a non-null and non-empty field.
For more details see https://opensearch.org/docs/latest/opensearch/query-dsl/term/#range-query
func NewRangeQuery ¶
func NewRangeQuery(field string) *RangeQuery
NewRangeQuery instantiates a Range Query targeting field. A RangeQuery with no range operations will function like an ExistsQuery and match all documents that contain the field.
func (*RangeQuery) Gt ¶
func (q *RangeQuery) Gt(value any) *RangeQuery
Gt sets the greater than value.
func (*RangeQuery) Gte ¶
func (q *RangeQuery) Gte(value any) *RangeQuery
Gte sets the greater than or equal to value.
func (*RangeQuery) Lte ¶
func (q *RangeQuery) Lte(value any) *RangeQuery
Lte sets the less than or equal to value.
func (*RangeQuery) ToOpenSearchJSON ¶
func (q *RangeQuery) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the RangeQuery to the correct OpenSearch JSON.
type Refresh ¶
type Refresh string
Refresh is a common query parameter across OpenSearch write requests
More details can be found on https://opensearch.org/docs/latest/api-reference/document-apis/bulk/
const ( // True - make the write operation immediately available for search True Refresh = "true" // False - default, do not wait for the write operation to be available for search False Refresh = "false" // WaitFor - waits for the normal index refresh to make the write operation searchable WaitFor Refresh = "wait_for" )
type RegexQuery ¶
type RegexQuery struct {
// contains filtered or unexported fields
}
RegexQuery allows you to search on a targeted field matching on values that fit the regular expression. An empty Regex will be rejected by OpenSearch for two reasons:
- a field must not be empty or null
- a value must be non-null
For more details see https://opensearch.org/docs/latest/opensearch/query-dsl/term/#regex
func NewRegexQuery ¶
func NewRegexQuery(field, regex string) *RegexQuery
NewRegexQuery instantiates a RegexQuery targeting field with pattern regex.
func (*RegexQuery) ToOpenSearchJSON ¶
func (q *RegexQuery) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the RegexQuery to the correct OpenSearch JSON.
type RoutableDoc ¶
type RoutableDoc interface { // Index returns the index the document should be routed to Index() string // ID returns the document ID ID() string }
RoutableDoc interface defines an OpenSearch document that can be routed to a specific index. The most basic implementation is DocumentRef.
type Search ¶
type Search interface {
Search(ctx context.Context, req *SearchRequest) (OpenSearchResponse[SearchResponse], error)
}
Search defines a method which knows how to make an OpenSearch Search request. It should be implemented by a version-specific executor.
type SearchRequest ¶
type SearchRequest struct { // Query to be performed by the search Query Query // Index(s) to be targeted by the search Index []string // Size of results to be returned Size int // From the starting index to search from From int // Sort(s) to order the results returned Sort []Sort // TrackTotalHits - whether to return how many documents matched the query. TrackTotalHits any // Routing - Values used to route the update by query operation to a specific shard Routing []string // Aggregations to be performed on the results of the Query Aggregations map[string]Aggregation }
SearchRequest is a domain model union type for all the fields of a Search request across all supported OpenSearch versions. Currently supported versions are:
- OpenSearch 2
This SearchRequest is intended to be used along with a version-specific executor such as opensearchtools/osv2.Executor. For example:
searchReq := NewSearchRequest(). WithQuery(NewTermQuery("field", "term")) searchResp, err := osv2Executor.Search(ctx, searchReq)
An error can be returned if
- The request to OpenSearch fails
- The results json cannot be unmarshalled
func NewSearchRequest ¶
func NewSearchRequest() *SearchRequest
NewSearchRequest instantiates a SearchRequest with a From and Size of -1. Any negative value for SearchRequest.From or SearchRequest.Size will be ignored and not included in the source. Opensearch by default, if no size is included in a search request, will limit the results to 10 documents. Opensearch by default, if no from is included in a search request, will return hits starting from the first hit based on the sort. A NewSearchRequest will search across all indices and return the top 10 documents with the default sorting.
func (*SearchRequest) AddAggregation ¶
func (r *SearchRequest) AddAggregation(name string, agg Aggregation) *SearchRequest
AddAggregation to the search request with the desired name
func (*SearchRequest) AddIndices ¶
func (r *SearchRequest) AddIndices(indices ...string) *SearchRequest
AddIndices sets the index list for the request.
func (*SearchRequest) AddSorts ¶
func (r *SearchRequest) AddSorts(sort ...Sort) *SearchRequest
AddSorts to the current list of [Sort]s on the request.
func (*SearchRequest) WithFrom ¶ added in v0.5.0
func (r *SearchRequest) WithFrom(n int) *SearchRequest
WithFrom sets the request's starting index for the result hits. A negative value for from will be ignored and not included in the SearchRequest.Source.
func (*SearchRequest) WithQuery ¶
func (r *SearchRequest) WithQuery(q Query) *SearchRequest
WithQuery to be performed by the SearchRequest.
func (*SearchRequest) WithRouting ¶
func (r *SearchRequest) WithRouting(routing ...string) *SearchRequest
WithRouting sets the routing value(s)
func (*SearchRequest) WithSize ¶
func (r *SearchRequest) WithSize(n int) *SearchRequest
WithSize sets the request size, limiting the number of documents returned. A negative value for size will be ignored and not included in the SearchRequest.Source.
func (*SearchRequest) WithTrackTotalHits ¶
func (r *SearchRequest) WithTrackTotalHits(track any) *SearchRequest
WithTrackTotalHits if set to true it will count all documents, otherwise a number can be set to limit the counting ceiling.
type SearchResponse ¶
type SearchResponse struct { // Took the time in Milliseconds OpenSearch took to execute the query Took int // TimedOut true if the request timed out TimedOut bool // Shards [ShardMeta] counts of the shards used in the request processing Shards ShardMeta // Hits are the results of the [Query] Hits Hits // Error if OpenSearch failed but responded with errors Error *Error // Aggregations response if any were requested Aggregations map[string]json.RawMessage }
SearchResponse is a domain model union response type across all supported OpenSearch versions. Currently supported versions are:
-OpenSearch2
func (SearchResponse) GetAggregationResultSource ¶
func (sr SearchResponse) GetAggregationResultSource(name string) ([]byte, bool)
GetAggregationResultSource implements opensearchtools.AggregationResultSet to fetch an aggregation result and return the raw JSON source for the provided name.
func (SearchResponse) Keys ¶
func (sr SearchResponse) Keys() []string
Keys implemented for opensearchtools.AggregationResultSet to return the list of aggregation result keys
type ShardMeta ¶
ShardMeta contains information about the shards used or interacted with to perform a given OpenSearch Request.
type SingleValueAggType ¶
type SingleValueAggType string
SingleValueAggType represents valid single value metric aggregations
type SingleValueAggregationResult ¶
type SingleValueAggregationResult struct { // Value will return nil if not metrics were aggregated Value *float64 `json:"value,omitempty"` // ValueString is optional depending on the field type of the value being aggregated ValueString string `json:"value_as_string,omitempty"` }
SingleValueAggregationResult union of the single-value metric aggregations results.
type SingleValueMetricAggregation ¶
type SingleValueMetricAggregation struct { // Type of metric aggregation to be performed Type SingleValueAggType // Field to be bucketed Field string // PrecisionThreshold is used only for CardinalityAggregation. It defines the // threshold below which counts are expected to be close to accurate. // Negative values will be omitted PrecisionThreshold int // Missing is used to define how documents missing the target field should be treated. // The value of Missing is substituted for the document. Missing any }
SingleValueMetricAggregation is a union of the single-value metric aggregations.
- Cardinality
- Sum
- Min
- Max
- Average
Metric aggregations let you perform simple calculations on values of a field. An empty SingleValueMetricAggregation will have some issues with execution:
- the target Field must be non-nil and non-empty
- the Type field must be non-empty and matching a SingleValueAggType
For more details see https://opensearch.org/docs/latest/opensearch/metric-agg
func NewAverageAggregation ¶
func NewAverageAggregation(field string) *SingleValueMetricAggregation
NewAverageAggregation instantiates a SingleValueMetricAggregation with type AverageAggregation, targeting the provided field. Sets PrecisionThreshold to -1 to be omitted.
func NewCardinalityAggregation ¶
func NewCardinalityAggregation(field string) *SingleValueMetricAggregation
NewCardinalityAggregation instantiates a SingleValueMetricAggregation with type CardinalityAggregation, targeting the provided field. Sets PrecisionThreshold to -1 to be omitted.
func NewMaximumAggregation ¶
func NewMaximumAggregation(field string) *SingleValueMetricAggregation
NewMaximumAggregation instantiates a SingleValueMetricAggregation with type MaximumAggregation, targeting the provided field. Sets PrecisionThreshold to -1 to be omitted.
func NewMinimumAggregation ¶
func NewMinimumAggregation(field string) *SingleValueMetricAggregation
NewMinimumAggregation instantiates a SingleValueMetricAggregation with type MinimumAggregation, targeting the provided field. Sets PrecisionThreshold to -1 to be omitted.
func NewSumAggregation ¶
func NewSumAggregation(field string) *SingleValueMetricAggregation
NewSumAggregation instantiates a SingleValueMetricAggregation with type SumAggregationion, targeting the provided field. Sets PrecisionThreshold to -1 to be omitted.
func (*SingleValueMetricAggregation) ToOpenSearchJSON ¶
func (s *SingleValueMetricAggregation) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the SingleValueMetricAggregation to the correct OpenSearch JSON. Implements [Aggregation.ToOpenSearchJSON].
func (*SingleValueMetricAggregation) Validate ¶
func (s *SingleValueMetricAggregation) Validate() ValidationResults
Validate that the aggregation is executable. Implements [Aggregation.Validate].
func (*SingleValueMetricAggregation) WithMissing ¶
func (s *SingleValueMetricAggregation) WithMissing(missing any) *SingleValueMetricAggregation
WithMissing value to use
func (*SingleValueMetricAggregation) WithPrecisionThreshold ¶
func (s *SingleValueMetricAggregation) WithPrecisionThreshold(p int) *SingleValueMetricAggregation
WithPrecisionThreshold sets the PrecisionThreshold
type Sort ¶
Sort encapsulates the sort capabilities for OpenSearch. An empty Sort will be rejected by OpenSearch as a field must be non-null and non-empty.
For more details see https://opensearch.org/docs/latest/opensearch/search/sort/
func NewSort ¶
NewSort instantiates a search Sort with the field to be sorted and whether is descending or ascending.
func (*Sort) ToOpenSearchJSON ¶
ToOpenSearchJSON converts the Sort to the correct OpenSearch JSON.
type TermBucketResult ¶
type TermBucketResult struct { Key string DocCount int64 SubAggregationResults map[string]json.RawMessage }
TermBucketResult is a [AggregationResultMap] for a TermsAggregation
func (*TermBucketResult) GetAggregationResultSource ¶
func (t *TermBucketResult) GetAggregationResultSource(name string) ([]byte, bool)
GetAggregationResultSource implements opensearchtools.AggregationResultSet to fetch a sub aggregation result and return the raw JSON source for the provided name.
func (*TermBucketResult) Keys ¶
func (t *TermBucketResult) Keys() []string
Keys implemented for opensearchtools.AggregationResultSet to return the list of aggregation result keys
func (*TermBucketResult) UnmarshalJSON ¶
func (t *TermBucketResult) UnmarshalJSON(m []byte) error
UnmarshalJSON implements json.Unmarshaler to decode a json byte slice into a TermBucketResult
type TermQuery ¶
type TermQuery struct {
// contains filtered or unexported fields
}
TermQuery finds documents that have the field matching the exact value. An empty TermQuery will be rejected by OpenSearch for two reasons:
- a field must not be empty or null
- a value must be non-null
For more details see https://opensearch.org/docs/latest/opensearch/query-dsl/term/
func NewTermQuery ¶
NewTermQuery initializes a TermQuery targeting field looking for the exact value.
func (*TermQuery) ToOpenSearchJSON ¶
ToOpenSearchJSON converts the TermQuery to the correct OpenSearch JSON.
type TermsAggregation ¶
type TermsAggregation struct { // Field to be bucketed Field string // Size of the number of buckets to be returned. Negative sizes will be omitted Size int // MinDocCount is the lower count threshold for a bucket to be included in the results. // Negative counts will be omitted MinDocCount int64 // Missing counts documents that are missing the field being aggregated Missing string // Include filters values based on a regexp, Include cannot be used in tandem with IncludeValues Include string // IncludeValues filters values base on a list of exact matches, // IncludeValues cannot be used in tandem with Include IncludeValues []string // Exclude filters values based on a regexp, Exclude cannot be used in tandem with ExcludeValues Exclude string // ExcludeValues filters values base on a list of exact matches, // ExcludeValues cannot be used in tandem with Exclude ExcludeValues []string // Order list of [Order]s to sort the aggregation buckets. Default order is _count: desc Order []Order // Aggregations sub aggregations for each bucket. Mapped by string label to sub aggregation Aggregations map[string]Aggregation }
TermsAggregation dynamically creates a bucket for each unique term of a field. An empty TermsAggregation will have some issues with execution:
- the target Field must be non-nil and non-empty.
- a Size of 0 will return no buckets
For more details see https://opensearch.org/docs/latest/opensearch/bucket-agg/
func NewTermsAggregation ¶
func NewTermsAggregation(field string) *TermsAggregation
NewTermsAggregation instantiates a TermsAggregation targeting the provided field. Sets Size and MinDocCount to -1 to be omitted for the default value.
func (*TermsAggregation) AddOrder ¶
func (t *TermsAggregation) AddOrder(orders ...Order) *TermsAggregation
AddOrder of the returned buckets
func (*TermsAggregation) AddSubAggregation ¶
func (t *TermsAggregation) AddSubAggregation(name string, agg Aggregation) BucketAggregation
AddSubAggregation to the TermsAggregation with the provided name Implements [BucketAggregation.AddSubAggregation]
func (*TermsAggregation) SubAggregations ¶
func (t *TermsAggregation) SubAggregations() map[string]Aggregation
SubAggregations returns all aggregations added to the bucket aggregation. Implements [BucketAggregation.SubAggregations]
func (*TermsAggregation) ToOpenSearchJSON ¶
func (t *TermsAggregation) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the TermsAggregation to the correct OpenSearch JSON. Implements [Aggregation.ToOpenSearchJSON].
func (*TermsAggregation) Validate ¶
func (t *TermsAggregation) Validate() ValidationResults
Validate that the aggregation is executable. Implements [Aggregation.Validate].
func (*TermsAggregation) WithExclude ¶
func (t *TermsAggregation) WithExclude(exclude string) *TermsAggregation
WithExclude sets the regex exclude filter
func (*TermsAggregation) WithExcludes ¶
func (t *TermsAggregation) WithExcludes(excludes []string) *TermsAggregation
WithExcludes sets the list of Exclude matches
func (*TermsAggregation) WithInclude ¶
func (t *TermsAggregation) WithInclude(include string) *TermsAggregation
WithInclude sets the regex include filter
func (*TermsAggregation) WithIncludes ¶
func (t *TermsAggregation) WithIncludes(include []string) *TermsAggregation
WithIncludes sets the list of include matches
func (*TermsAggregation) WithMinDocCount ¶
func (t *TermsAggregation) WithMinDocCount(minCount int64) *TermsAggregation
WithMinDocCount the lower count threshold for a bucket to be included in the results
func (*TermsAggregation) WithMissing ¶
func (t *TermsAggregation) WithMissing(missing string) *TermsAggregation
WithMissing buckets documents missing the field under the provided label
func (*TermsAggregation) WithSize ¶
func (t *TermsAggregation) WithSize(size int) *TermsAggregation
WithSize for the number of buckets to be returned
type TermsAggregationResults ¶
type TermsAggregationResults struct { DocCountErrorUpperBound int64 SumOtherDocCount int64 Buckets []TermBucketResult }
TermsAggregationResults represents the results from a terms aggregation request.
func (*TermsAggregationResults) UnmarshalJSON ¶
func (t *TermsAggregationResults) UnmarshalJSON(m []byte) error
UnmarshalJSON implements json.Unmarshaler to decode a json byte slice into a TermsAggregationResults Errors on unknown fields.
type TermsQuery ¶
type TermsQuery struct {
// contains filtered or unexported fields
}
TermsQuery finds documents that have the field match one of the listed values. An empty TermsQuery will be rejected by OpenSearch for two reasons:
- a field must not be empty or null
- a value must be non-null
For more details see https://opensearch.org/docs/latest/opensearch/query-dsl/term/#terms
func NewTermsQuery ¶
func NewTermsQuery(field string, values ...any) *TermsQuery
NewTermsQuery instantiates a TermsQuery targeting field looking for one of the values.
func (*TermsQuery) ToOpenSearchJSON ¶
func (q *TermsQuery) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the TermsQuery to the correct OpenSearch JSON.
type Total ¶
Total is a domain model union response type across all supported OpenSearch versions. Currently supported versions are:
-OpenSearch2
Total contains the total number of documents found by the Query performed by the SearchRequest.
type ValidationError ¶
type ValidationError struct {
ValidationResults ValidationResults
}
ValidationError is an error which contains ValidationResults
func NewValidationError ¶
func NewValidationError(vrs ValidationResults) *ValidationError
NewValidationError creates a new ValidationError instance with the given ValidationResults
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error returns a newline-separated string representation of all validation results or an empty string if there are none. Fatal results are prefixed with `fatal:`.
type ValidationResult ¶
ValidationResult is an individual validation result item to be returned by a [ValidateForVersion] call.
func NewValidationResult ¶
func NewValidationResult(message string, fatal bool) ValidationResult
NewValidationResult creates a new ValidationResult instance with the given message and fatal params.
type ValidationResults ¶
type ValidationResults struct {
// contains filtered or unexported fields
}
A collection of ValidationResults that implements set logic, meaning it holds unique entries only (no duplicates)
func NewValidationResults ¶
func NewValidationResults() ValidationResults
NewValidationResults creates a new ValidationResults instance
func ValidationResultsFromSlice ¶
func ValidationResultsFromSlice(vrs []ValidationResult) ValidationResults
ValidationResultsFromSlice creates a ValidationResults from the given slice of ValidationResult
func (*ValidationResults) Add ¶
func (vrs *ValidationResults) Add(vr ValidationResult)
Add either adds the given ValidationResult to the set or does not if it already exists in the set
func (*ValidationResults) Extend ¶
func (vrs *ValidationResults) Extend(other ValidationResults)
Extend either adds the given ValidationResult to the set or does not if it already exists in the set
func (*ValidationResults) IsFatal ¶
func (vrs *ValidationResults) IsFatal() bool
IsFatal returns true if there is one or more ValidationResult that is fatal.
func (*ValidationResults) Len ¶ added in v0.3.0
func (vrs *ValidationResults) Len() int
Len returns the number of [ValidationResult]s in the current set
type Validator ¶
type Validator interface {
Validate() ValidationResults
}
Validator defines the behavior for validating a domain model object.
type WildcardQuery ¶
type WildcardQuery struct {
// contains filtered or unexported fields
}
WildcardQuery searches for documents with a field matching a wildcard pattern. An empty TermQuery will be rejected by OpenSearch for two reasons:
- a field must not be empty or null
- a value must be non-null
For more details see https://opensearch.org/docs/latest/opensearch/query-dsl/term/#wildcards
func NewWildcardQuery ¶
func NewWildcardQuery(field, value string) *WildcardQuery
NewWildcardQuery instantiates a wildcard query targeting field looking for a wildcard match on value.
func (*WildcardQuery) ToOpenSearchJSON ¶
func (q *WildcardQuery) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON converts the WildcardQuery to the correct OpenSearch JSON.
Source Files
¶
- bulk.go
- bulk_action.go
- document.go
- error.go
- mget.go
- pointer_constraint.go
- refresh.go
- response.go
- search.go
- search_agg.go
- search_agg_bucket_sort.go
- search_agg_date_histogram.go
- search_agg_date_range.go
- search_agg_filter.go
- search_agg_order.go
- search_agg_percentiles.go
- search_agg_range.go
- search_agg_single_value_metric.go
- search_agg_terms.go
- search_query.go
- search_query_boolean.go
- search_query_exists.go
- search_query_match.go
- search_query_match_all.go
- search_query_match_phrase.go
- search_query_nested.go
- search_query_prefix.go
- search_query_range.go
- search_query_regex.go
- search_query_term.go
- search_query_terms.go
- search_query_wildcard.go
- search_sort.go
- shard_meta.go
- validation.go