elasticsearch

package
v1.26.13 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MultiMatchTypeBestFields   = "best_fields"
	MultiMatchTypePhrasePrefix = "phrase_prefix"
)

MultiMatch types used by the call sites. See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#multi-match-types

Variables

This section is empty.

Functions

func ToAnySlice

func ToAnySlice[T any](s []T) []any

ToAnySlice converts []T to []any for variadic query args like TermsQuery.

Types

type AggBucket

type AggBucket struct {
	Key      any
	DocCount int64
}

AggBucket is a terms-aggregation bucket.

type BoolQuery

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

BoolQuery is the fluent builder for a bool query.

func NewBoolQuery

func NewBoolQuery() *BoolQuery

func (*BoolQuery) Must

func (b *BoolQuery) Must(q ...Query) *BoolQuery

func (*BoolQuery) MustNot

func (b *BoolQuery) MustNot(q ...Query) *BoolQuery

func (*BoolQuery) Should

func (b *BoolQuery) Should(q ...Query) *BoolQuery

type BulkOp

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

BulkOp is a single write inside a Bulk call. Construct with IndexOp or DeleteOp.

func DeleteOp

func DeleteOp(id string) BulkOp

DeleteOp builds a bulk delete operation.

func IndexOp

func IndexOp(id string, doc any) BulkOp

IndexOp builds a bulk index operation.

type Indexer

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

Indexer is a narrow wrapper around an Elasticsearch/OpenSearch cluster. It targets the REST subset shared by Elasticsearch 7/8/9 and OpenSearch 3.

func NewIndexer

func NewIndexer(rawURL, indexName string, version int, mapping string) *Indexer

NewIndexer builds an Indexer. The connection is opened by Init.

func (*Indexer) Bulk

func (i *Indexer) Bulk(ctx context.Context, ops []BulkOp) error

Bulk submits index/delete ops. Returns the first item-level failure, if any.

func (*Indexer) Close

func (i *Indexer) Close()

Close releases idle HTTP connections held by the client.

func (*Indexer) Delete

func (i *Indexer) Delete(ctx context.Context, id string) error

Delete removes a single document by id. Missing ids are not an error.

func (*Indexer) DeleteByQuery

func (i *Indexer) DeleteByQuery(ctx context.Context, query Query) error

DeleteByQuery removes every document matching the query.

func (*Indexer) Index

func (i *Indexer) Index(ctx context.Context, id string, doc any) error

Index writes a single document.

func (*Indexer) Init

func (i *Indexer) Init(ctx context.Context) (bool, error)

Init connects and creates the versioned index if missing, returning true if it already existed.

func (*Indexer) Ping

func (i *Indexer) Ping(ctx context.Context) error

Ping returns an error when the cluster is unusable (status != green/yellow).

func (*Indexer) Refresh

func (i *Indexer) Refresh(ctx context.Context) error

Refresh forces a refresh so recent writes are searchable.

func (*Indexer) Search

func (i *Indexer) Search(ctx context.Context, req SearchRequest) (*SearchResponse, error)

Search runs a search request and decodes the reply.

func (*Indexer) VersionedIndexName

func (i *Indexer) VersionedIndexName() string

VersionedIndexName returns the full index name with version suffix.

type MultiMatchQuery

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

MultiMatchQuery is the fluent builder for a multi_match query.

func NewMultiMatchQuery

func NewMultiMatchQuery(query any, fields ...string) *MultiMatchQuery

NewMultiMatchQuery creates a multi_match query over the given fields.

func (*MultiMatchQuery) Operator

func (m *MultiMatchQuery) Operator(op string) *MultiMatchQuery

func (*MultiMatchQuery) Type

type Query

type Query interface {
	// contains filtered or unexported methods
}

Query is an Elasticsearch query DSL node. It marshals to the JSON object expected by the ES query API.

func MatchPhraseQuery

func MatchPhraseQuery(field, value string) Query

MatchPhraseQuery matches the exact phrase on `field`.

func MatchQuery

func MatchQuery(field string, value any) Query

MatchQuery is a full-text match on a single field.

func TermQuery

func TermQuery(field string, value any) Query

TermQuery matches documents whose `field` exactly equals `value`.

func TermsQuery

func TermsQuery(field string, values ...any) Query

TermsQuery matches documents whose `field` equals any of `values`.

type RangeQuery

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

RangeQuery is the fluent builder for a range query.

func NewRangeQuery

func NewRangeQuery(field string) *RangeQuery

func (*RangeQuery) Gte

func (r *RangeQuery) Gte(v any) *RangeQuery

func (*RangeQuery) Lte

func (r *RangeQuery) Lte(v any) *RangeQuery

type SearchHit

type SearchHit struct {
	ID        string
	Score     float64
	Source    json.Value
	Highlight map[string][]string
}

SearchHit is a single result row.

type SearchRequest

type SearchRequest struct {
	Query        Query
	Sort         []SortField
	From         int
	Size         int
	TrackTotal   bool
	Aggregations map[string]any
	Highlight    map[string]any
}

SearchRequest captures everything Gitea sends to the _search endpoint. Aggregations and Highlight are raw ES JSON bodies — callers write them as map[string]any since each has exactly one call site with a fixed shape.

type SearchResponse

type SearchResponse struct {
	Total        int64
	Hits         []SearchHit
	Aggregations map[string][]AggBucket
}

SearchResponse is Gitea's decoded view of the search reply.

type SortField

type SortField struct {
	Field string
	Desc  bool
}

SortField is one entry of the search sort array.

Jump to

Keyboard shortcuts

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