Documentation ¶
Index ¶
- func V2AggregateConverter(agg opensearchtools.Aggregation) (opensearchtools.Aggregation, error)
- func V2QueryConverter(query opensearchtools.Query) (opensearchtools.Query, error)
- type BulkRequest
- func (r *BulkRequest) Add(actions ...opensearchtools.BulkAction) *BulkRequest
- func (r *BulkRequest) Do(ctx context.Context, client *opensearch.Client) (*opensearchtools.OpenSearchResponse[BulkResponse], error)
- func (r *BulkRequest) ToOpenSearchJSON() ([]byte, error)
- func (r *BulkRequest) Validate() opensearchtools.ValidationResults
- func (r *BulkRequest) WithIndex(index string) *BulkRequest
- type BulkResponse
- type Error
- type Executor
- func (e *Executor) Bulk(ctx context.Context, req *opensearchtools.BulkRequest) (resp opensearchtools.OpenSearchResponse[opensearchtools.BulkResponse], ...)
- func (e *Executor) MGet(ctx context.Context, req *opensearchtools.MGetRequest) (resp opensearchtools.OpenSearchResponse[opensearchtools.MGetResponse], ...)
- func (e *Executor) Search(ctx context.Context, req *opensearchtools.SearchRequest) (resp opensearchtools.OpenSearchResponse[opensearchtools.SearchResponse], ...)
- type Hit
- type Hits
- type MGetRequest
- func (m *MGetRequest) Add(index, id string) *MGetRequest
- func (m *MGetRequest) AddDocs(docs ...opensearchtools.RoutableDoc) *MGetRequest
- func (m *MGetRequest) Do(ctx context.Context, client *opensearch.Client) (*opensearchtools.OpenSearchResponse[MGetResponse], error)
- func (m *MGetRequest) MarshalJSON() ([]byte, error)
- func (m *MGetRequest) WithIndex(index string) *MGetRequest
- type MGetResponse
- type MGetResult
- type SearchRequest
- func (r *SearchRequest) AddAggregation(name string, agg opensearchtools.Aggregation) *SearchRequest
- func (r *SearchRequest) AddIndices(indices ...string) *SearchRequest
- func (r *SearchRequest) AddSorts(sort ...opensearchtools.Sort) *SearchRequest
- func (r *SearchRequest) Do(ctx context.Context, client *opensearch.Client) (*opensearchtools.OpenSearchResponse[SearchResponse], error)
- func (r *SearchRequest) ToOpenSearchJSON() ([]byte, error)
- func (r *SearchRequest) Validate() opensearchtools.ValidationResults
- func (r *SearchRequest) WithFrom(n int) *SearchRequest
- func (r *SearchRequest) WithQuery(q opensearchtools.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 Total
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func V2AggregateConverter ¶
func V2AggregateConverter(agg opensearchtools.Aggregation) (opensearchtools.Aggregation, error)
V2AggregateConverter will do any translations needed from domain level queries into V2 specifics, if needed.
func V2QueryConverter ¶
func V2QueryConverter(query opensearchtools.Query) (opensearchtools.Query, error)
V2QueryConverter will do any translations needed from domain level queries into V2 specifics, if needed.
Types ¶
type BulkRequest ¶
type BulkRequest struct { // Actions lists the actions to be performed in the BulkRequest Actions []opensearchtools.BulkAction // Refresh determines if the request should wait for a refresh or not Refresh opensearchtools.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 serializable form of opensearchtools.BulkRequest specific to the opensearchapi.BulkRequest in OpenSearch V2. An empty BulkRequest will fail to execute. At least one Action is required to be added.
For more details see https://opensearch.org/docs/latest/api-reference/document-apis/bulk/
func FromDomainBulkRequest ¶
func FromDomainBulkRequest(req *opensearchtools.BulkRequest) (BulkRequest, opensearchtools.ValidationResults)
FromDomainBulkRequest creates a new BulkRequest from the given [opensearchtools.BulkRequest/.
func NewBulkRequest ¶
func NewBulkRequest() *BulkRequest
NewBulkRequest instantiates an empty BulkRequest
func (*BulkRequest) Add ¶
func (r *BulkRequest) Add(actions ...opensearchtools.BulkAction) *BulkRequest
Add an action to the BulkRequest.
func (*BulkRequest) Do ¶
func (r *BulkRequest) Do(ctx context.Context, client *opensearch.Client) (*opensearchtools.OpenSearchResponse[BulkResponse], error)
Do executes the BulkRequest using the provided opensearch.Client. If the request is executed successfully, then a BulkResponse will be returned. An error can be returned if
- Any Action is missing an action
- The call to OpenSearch fails
- The result json cannot be unmarshalled
func (*BulkRequest) ToOpenSearchJSON ¶
func (r *BulkRequest) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON marshals the BulkRequest into the JSON format expected by OpenSearch. Note: A BulkRequest is multi-line json with new line delimiters. It is not a singular valid json struct. For example:
{ action1 json } { action2 json }
func (*BulkRequest) Validate ¶
func (r *BulkRequest) Validate() opensearchtools.ValidationResults
Validate validates the given BulkRequest
func (*BulkRequest) WithIndex ¶
func (r *BulkRequest) WithIndex(index string) *BulkRequest
WithIndex on the request
type BulkResponse ¶
type BulkResponse struct { Took int64 `json:"took"` Errors bool `json:"errors"` Items []opensearchtools.ActionResponse `json:"items"` Error *Error `json:"error,omitempty"` }
BulkResponse wraps the functionality of opensearchapi.Response by unmarshalling the api response into a slice of [bulk.ActionResponse].
type Error ¶
type Error struct { RootCause []Error `json:"root_cause"` Type string `json:"type"` Reason string `json:"reason"` Index string `json:"index"` ResourceID string `json:"resource.id"` ResourceType string `json:"resource.type"` IndexUUID string `json:"index_uuid"` }
Error encapsulates an error response from a given OpenSearch request.
type Executor ¶
type Executor struct {
// OpenSearch 2 specifc client
Client *opensearch.Client
}
Executor is an executor for OpenSearch 2.
func NewExecutor ¶
func NewExecutor(client *opensearch.Client) *Executor
NewExecutor creates a new osv2.Executor instance.
func (*Executor) Bulk ¶
func (e *Executor) Bulk(ctx context.Context, req *opensearchtools.BulkRequest) (resp opensearchtools.OpenSearchResponse[opensearchtools.BulkResponse], err error)
Bulk executes the BulkRequest using the provided opensearchtools.BulkRequest. If the request is executed successfully, then an opensearchtools.OpenSearchResponse containing a opensearchtools.BulkResponse An error can be returned if:
- The request to OpenSearch fails
- The results json cannot be unmarshalled
func (*Executor) MGet ¶
func (e *Executor) MGet(ctx context.Context, req *opensearchtools.MGetRequest) (resp opensearchtools.OpenSearchResponse[opensearchtools.MGetResponse], err error)
MGet executes the Multi-Get MGetRequest using the provided opensearchtools.MGetRequest. If the request is executed successfully, then an opensearchtools.MGetResponse with opensearchtools.MGetResults will be returned. An error can be returned if:
- Fatal validation issues are found
- The request to OpenSearch fails
- The results JSON cannot be unmarshalled
func (*Executor) Search ¶
func (e *Executor) Search(ctx context.Context, req *opensearchtools.SearchRequest) (resp opensearchtools.OpenSearchResponse[opensearchtools.SearchResponse], err error)
Search executes the SearchRequest using the provided opensearchtools.SearchRequest. If the request is executed successfully, then an opensearchtools.SearchResponse will be returned. An error can be returned if:
- Fatal validation issues are found
- The request to OpenSearch fails
- The results JSON cannot be unmarshalled
type Hit ¶
type Hit struct { Index string `json:"_index"` ID string `json:"_id"` Score float64 `json:"_score"` Source json.RawMessage `json:"_source"` }
Hit the individual document found by the `[opensearchtools.Query] performed by the SearchRequest.
type Hits ¶
type Hits struct { Total Total `json:"total,omitempty"` MaxScore float64 `json:"max_score,omitempty"` Hits []Hit `json:"hits"` }
Hits represent the results of the opensearchtools.Query performed by the SearchRequest.
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 []opensearchtools.RoutableDoc }
MGetRequest is a marshalable form of opensearchtools.MGetRequest specific to the opensearchapi.MgetRequest in OpenSearch v2.
func FromDomainMGetRequest ¶
func FromDomainMGetRequest(req *opensearchtools.MGetRequest) (MGetRequest, opensearchtools.ValidationResults)
FromDomainMGetRequest creates a new MGetRequest from the given opensearchtools.MGetRequest.
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 opensearchtools.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 ...opensearchtools.RoutableDoc) *MGetRequest
AddDocs - add any number opensearchtools.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) Do ¶
func (m *MGetRequest) Do(ctx context.Context, client *opensearch.Client) (*opensearchtools.OpenSearchResponse[MGetResponse], error)
Do executes the Multi-Get MGetRequest using the provided OpenSearch v2 opensearch.Client. If the request is executed successfully, then a MGetResponse with MGetResults will be returned. We can perform an MGetRequest as simply as:
mgetResults, mgetError := NewMGetRequest(). Add("example_index", "example_id"). Do(context.background(), client)
An error can be returned if
- The request to OpenSearch fails
- The results json cannot be unmarshalled
func (*MGetRequest) MarshalJSON ¶
func (m *MGetRequest) MarshalJSON() ([]byte, error)
MarshalJSON marshals the MGetRequest into the proper json expected by OpenSearch 2.
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 `json:"docs,omitempty"`
}
MGetResponse is an OpenSearch 2 specific struct corresponding to opensearchapi.Response and opensearchtools.MGetResponse. It holds a slice of mgetResults.
type MGetResult ¶
type MGetResult struct { Index string `json:"_index,omitempty"` ID string `json:"_id,omitempty"` Version int `json:"_version,omitempty"` SeqNo int `json:"_seq_no,omitempty"` PrimaryTerm int `json:"_primary_term,omitempty"` Found bool `json:"found,omitempty"` Source json.RawMessage `json:"_source,omitempty"` Error error `json:"-"` }
MGetResult is the individual result for each requested item.
type SearchRequest ¶
type SearchRequest struct { // Query to be performed by the search Query opensearchtools.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 []opensearchtools.Sort // TrackTotalHits - whether to return how many documents matched the query. TrackTotalHits any // Routing - Value(s) 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]opensearchtools.Aggregation }
SearchRequest is a serializable form of opensearchtools.SearchRequest specific to the opensearchapi.SearchRequest in OpenSearch V2. An empty SearchRequest defaults to a size of 0. While this will find matches and return a total hits value, it will return no documents. It is recommended to use NewSearchRequest or use WithSize. A simple term query search as an example:
req := NewSearchRequest() req.AddIndices("example_index") req.WithQuery(opensearchtools.NewTermQuery("field", "basic") results, err := req.Do(context.Background(), client)
func FromDomainSearchRequest ¶
func FromDomainSearchRequest(req *opensearchtools.SearchRequest) (SearchRequest, opensearchtools.ValidationResults)
FromDomainSearchRequest creates a new SearchRequest from the given opensearchtools.SearchRequest
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 opensearchtools.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 ...opensearchtools.Sort) *SearchRequest
AddSorts to the current list of [opensearchtools.Sort]s on the request.
func (*SearchRequest) Do ¶
func (r *SearchRequest) Do(ctx context.Context, client *opensearch.Client) (*opensearchtools.OpenSearchResponse[SearchResponse], error)
Do executes the SearchRequest using the provided opensearch.Client. If the request is executed successfully, then a SearchResponse will be returned. An error can be returned if
- The SearchRequest source cannot be created
- The source fails to be marshaled to JSON
- The OpenSearch request fails to executed
- The OpenSearch response cannot be parsed
func (*SearchRequest) ToOpenSearchJSON ¶
func (r *SearchRequest) ToOpenSearchJSON() ([]byte, error)
ToOpenSearchJSON marshals the SearchRequest into the JSON shape expected by OpenSearch.
func (*SearchRequest) Validate ¶
func (r *SearchRequest) Validate() opensearchtools.ValidationResults
Validate validates the given SearchRequest
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 opensearchtools.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 int `json:"took"` TimedOut bool `json:"timed_out"` Shards ShardMeta `json:"_shards,omitempty"` Hits Hits `json:"hits"` Error *Error `json:"error,omitempty"` Aggregations map[string]json.RawMessage `json:"aggregations,omitempty"` }
SearchResponse wraps the functionality of opensearchapi.Response by supporting request parsing.
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 ¶
type ShardMeta struct { Total int `json:"total"` Successful int `json:"successful"` Skipped int `json:"skipped"` Failed int `json:"failed"` }
ShardMeta contains information about the shards used or interacted with to perform a given OpenSearch Request.
type Total ¶
Total contains the total number of documents found by the opensearchtools.Query performed by the SearchRequest.