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 ¶
- func SearchTargetName(_ string, modelVersion int) string
- type Adapter
- func (a *Adapter) AggregateVersions(ctx context.Context, tenantID string, ent *registry.Entity) (map[string]int64, error)
- func (a *Adapter) ApplyMutations(ctx context.Context, target string, muts []projection.Mutation) error
- func (a *Adapter) DropTarget(ctx context.Context, target string) error
- func (a *Adapter) FlipAliases(ctx context.Context, tenantID string, _, newVersion int) error
- func (a *Adapter) Search(ctx context.Context, q query.SearchQuery, into any) error
- type Config
- type ModelVersionResolver
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SearchTargetName ¶
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 (*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 ¶
DropTarget deletes one model version's indexes for a tenant (rebuild cleanup). target is a "vN" tag.
func (*Adapter) FlipAliases ¶
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 ¶
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 ModelVersionResolver ¶
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.