results

package
v0.96.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExtractSource      = errors.New("could not extract document _source")
	ErrRequestFailed      = errors.New("request failed")
	ErrFieldNotFound      = errors.New("field not found")
	ErrInvalidAPIResponse = errors.New("invalid API response")
)

Functions

func ExtractFieldFromHits

func ExtractFieldFromHits[T any](field string, hits []types.Hit) (map[string]T, error)

ExtractFieldFromHits loops through the given hits array and extracts the `_source` field of each document as type `T`, returning the document sources as an array `[]T`. If there was an issue extracting any source, it will also return a non-nil error containing details.

func ExtractFieldValue

func ExtractFieldValue[T any](field string, fields map[string]json.RawMessage) (T, error)

ExtractFieldValue extracts the value of the given field from a hit's list of returned fields. If the field is not found or the value cannot be extracted, a non-nil error is returned.

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#search-fields-param

func ExtractSource

func ExtractSource[T any](doc json.RawMessage) (T, error)

ExtractSource extracts the `_source` field from a hit. A non-nil error is returned if the source cannot be extracted.

func ExtractSourceFromDocs

func ExtractSourceFromDocs[T any](docs []types.MgetResponseItem) ([]T, error)

ExtractSourceFromDocs loops through the given docs array and extracts the `_source` field of each document as type `T`, returning the document sources as an array `[]T`. If there was an issue extracting any source, it will also return a non-nil error containing details.

func ExtractSourceFromHits

func ExtractSourceFromHits[T any](hits []types.Hit) ([]T, []types.FieldValue, error)

ExtractSourceFromHits loops through the given hits array and extracts the `_source` field of each document as type `T`, returning the document sources as an array `[]T`. If there was an issue extracting any source, it will also return a non-nil error containing details. The sort value of the last hit will also be returned, which can be used for pagination if needed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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