elastic

package module
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

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

View Source
const (
	DefaultMaxBulkBytes = 5_000_000
	DefaultIndexName    = "scope-vector-index"
)
View Source
const (
	DefaultMaxResponseBytes int64 = 16 << 20
)

Variables

View Source
var ErrResponseLimit = errors.New("elastic: native response exceeds MaxResponseBytes")

Functions

This section is empty.

Types

type BulkConfig

type BulkConfig struct {
	Index        string
	Operation    Operation
	MaxBytes     int
	AllowMissing bool
}

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

func (*BulkPlan) Delete

func (b *BulkPlan) Delete(id string, version *Version) error

func (*BulkPlan) Index

func (b *BulkPlan) Index(id string, doc any) error

func (*BulkPlan) Publish

func (b *BulkPlan) Publish(ctx context.Context, client *Client) error

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 Hit struct {
	Index       string                       `json:"_index"`
	ID          string                       `json:"_id"`
	Routing     string                       `json:"_routing"`
	Fields      map[string][]json.RawMessage `json:"fields"`
	SeqNo       *int64                       `json:"_seq_no"`
	PrimaryTerm *int64                       `json:"_primary_term"`
	Score       *float64                     `json:"_score"`
	Source      json.RawMessage              `json:"_source"`
}

func (Hit) Validate

func (h Hit) Validate() error

func (Hit) Version

func (h Hit) Version() (Version, error)

type Operation

type Operation string
const (
	Index  Operation = "index"
	Delete Operation = "delete"
)

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)

func (*Scroll) Select

func (s *Scroll) Select(ctx context.Context, predicate filter.Predicate) (selected map[string]Version, err 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

type SearchShards

type SearchShards struct {
	Total      *int `json:"total"`
	Successful *int `json:"successful"`
	Failed     *int `json:"failed"`
}

type SearchTotal

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

type Version

type Version struct {
	SeqNo       int64
	PrimaryTerm int64
}

func (Version) Validate

func (v Version) Validate() error

Jump to

Keyboard shortcuts

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