Documentation
¶
Overview ¶
Package elastic owns the shared Elasticsearch and OpenSearch bulk and scroll protocol. Native adapters keep their SDK transport, mapping, vector constraints, query syntax and record decoder; this module imports neither native SDK.
Client bounds every response before buffering and preserves received bytes together with read and closure errors. BulkPlan checks the entire encoded mutation before any publication, partitions it by bytes and action count, and keeps acknowledged, rejected, uncertain and unattempted IDs distinct. A valid receipt cannot erase a transport error, and a contradictory summary cannot establish per-document success.
Scroll validates complete shard acknowledgments, exact totals, unique document identities and cumulative scan budgets. Every observed cursor is eligible for cleanup even when its page was truncated. Cleanup errors invalidate the scan; cancellation does not relinquish ownership of the server cursor.
Index ¶
Examples ¶
Constants ¶
const ( DefaultMaxBulkBytes = 5_000_000 DefaultIndexName = "scope-vector-index" )
const (
DefaultMaxResponseBytes int64 = 16 << 20
)
Variables ¶
var ErrResponseLimit = errors.New("elastic: native response exceeds MaxResponseBytes")
Functions ¶
This section is empty.
Types ¶
type BulkConfig ¶
func (BulkConfig) Validate ¶
func (b BulkConfig) Validate() error
type BulkPlan ¶
type BulkPlan struct {
// contains filtered or unexported fields
}
BulkPlan admits every complete action before publication, so a late oversized record cannot leave an earlier mutation prefix applied. Plans have one operation.
func NewBulkPlan ¶
func NewBulkPlan(config BulkConfig) (*BulkPlan, error)
Example ¶
package main
import (
"fmt"
"github.com/Tangerg/scope/vectorstores/protocol/elastic"
)
func main() {
plan, err := elastic.NewBulkPlan(elastic.BulkConfig{
Index: "documents", Operation: elastic.Index, MaxBytes: 1 << 20,
})
if err != nil {
panic(err)
}
source := struct {
Text string `json:"text"`
}{Text: "Searchable content"}
if err := plan.Index("document-1", source); err != nil {
panic(err)
}
fmt.Println("complete document admitted")
}
Output: complete document admitted
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client owns bounded response consumption and closure. Perform borrows the host's native streaming transport without changing its retry or auth policy.
func NewClient ¶
func NewClient(config ClientConfig) (*Client, error)
func (*Client) Read ¶
func (c *Client) Read(ctx context.Context, method, path string, query url.Values, body []byte, limit int64) (raw []byte, err error)
Read retains received bytes with their errors, because acknowledgments and scroll cleanup cursors can remain meaningful after a read or Close failure. A zero limit uses the client bound; a positive limit may only narrow it.
type ClientConfig ¶
type ClientConfig struct {
Perform func(*http.Request) (*http.Response, error)
MaxResponseBytes int64
}
func (ClientConfig) Validate ¶
func (c ClientConfig) Validate() error
type DocumentID ¶
type DocumentID string
func (DocumentID) Validate ¶
func (d DocumentID) Validate() error
type Hit ¶
type Scroll ¶
type Scroll struct {
// contains filtered or unexported fields
}
Scroll owns exhaustive, budgeted membership and cursor cleanup. Decode belongs to the native schema owner; this protocol cannot infer vector representations.
func NewScroll ¶
func NewScroll(config ScrollConfig) (*Scroll, error)
type ScrollConfig ¶
type ScrollConfig struct {
Client *Client
Index string
Request []byte
Budget vectorstore.ScanBudget
Decode func(Hit) (*document.Document, error)
}
type SearchHits ¶
type SearchHits struct {
Total *SearchTotal `json:"total"`
Hits *[]Hit `json:"hits"`
}
type SearchResponse ¶
type SearchResponse struct {
ScrollID string `json:"_scroll_id"`
TerminatedEarly *bool `json:"terminated_early"`
TimedOut *bool `json:"timed_out"`
Shards *SearchShards `json:"_shards"`
Hits *SearchHits `json:"hits"`
}
func (SearchResponse) Validate ¶
func (s SearchResponse) Validate(index string) error