elastic

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package elastic is fabriq's search adapter on go-elasticsearch.

Tenancy and blue-green routing live in index naming, derived solely from core/registry: reads hit the per-tenant ALIAS (fabriq_{tenant}_{base}), writes hit the versioned index behind it (fabriq_{tenant}_{base}_v{N}); rebuilds build _v{N+1} and swap the alias atomically. Idempotency is engine-side: every bulk op carries the aggregate version with version_type=external_gte, so stale replays are version conflicts (treated as success).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SearchTargetName

func SearchTargetName(_ string, modelVersion int) string

SearchTargetName is the Rebuilder naming function for the search projection: targets are version tags interpreted by this sink.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter implements query.SearchQuerier.

func Open

func Open(_ context.Context, cfg Config, reg *registry.Registry, opts ...Option) (*Adapter, error)

Open dials Elasticsearch and pings it.

func (*Adapter) AggregateVersions

func (a *Adapter) AggregateVersions(ctx context.Context, tenantID string, ent *registry.Entity) (map[string]int64, error)

AggregateVersions reads id -> version for one entity's documents from the tenant's alias — the reconciler's projection side. Capped at 10k documents per entity for v1 (the match_all page limit); larger tenants reconcile via counts first and need a scroll, which is noted in OPERATIONS.md.

func (*Adapter) ApplyMutations

func (a *Adapter) ApplyMutations(ctx context.Context, target string, muts []projection.Mutation) error

ApplyMutations implements the search projection write path: one _bulk request per batch, every op carrying the aggregate version with version_type=external_gte. Stale replays come back as version conflicts and count as success — that IS the idempotency gate working.

target "" routes to the tenant's live versioned indexes (alias kept pointing at them); target "vN" routes to a rebuild's building indexes.

func (*Adapter) DropTarget

func (a *Adapter) DropTarget(ctx context.Context, target string) error

DropTarget deletes one model version's indexes for a tenant (rebuild cleanup). target is a "vN" tag.

func (*Adapter) FlipAliases

func (a *Adapter) FlipAliases(ctx context.Context, tenantID string, _, newVersion int) error

FlipAliases atomically repoints every searchable entity's tenant alias at the new model version's indexes — the search projection's blue-green cutover, one _aliases call. Removals are derived from what ACTUALLY holds each alias (entities that never indexed a document have no old index, and a remove for a nonexistent pair would fail the whole atomic action set). Wire it as the Rebuilder's OnFlip.

func (*Adapter) Search

func (a *Adapter) Search(ctx context.Context, q query.SearchQuery, into any) error

Search implements query.SearchQuerier: a multi_match over the entity's DECLARED search fields against the tenant's alias, optionally narrowed by a structured Filter (non-scoring bool filter context), ordered by Sort and paginated by Offset. An absent alias (no document ever indexed for this tenant) is an empty result, not an error.

type Config

type Config struct {
	Addrs    []string
	Username string
	Password string
}

Config locates the Elasticsearch cluster.

type ModelVersionResolver

type ModelVersionResolver func(ctx context.Context, tenantID string) (int, error)

ModelVersionResolver reports the live search model version for a tenant (projection_state-backed in production; defaults to 1).

type Option

type Option func(*Adapter)

Option customizes the adapter.

func WithModelVersionResolver

func WithModelVersionResolver(fn ModelVersionResolver) Option

WithModelVersionResolver wires the projection_state-backed live version.

Jump to

Keyboard shortcuts

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