scroll

package
v9.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Run a scrolling search.

IMPORTANT: The scroll API is no longer recommend for deep pagination. If you need to preserve the index state while paging through more than 10,000 hits, use the `search_after` parameter with a point in time (PIT).

The scroll API gets large sets of results from a single scrolling search request. To get the necessary scroll ID, submit a search API request that includes an argument for the `scroll` query parameter. The `scroll` parameter indicates how long Elasticsearch should retain the search context for the request. The search response returns a scroll ID in the `_scroll_id` response body parameter. You can then use the scroll ID with the scroll API to retrieve the next batch of results for the request. If the Elasticsearch security features are enabled, the access to the results of a specific scroll ID is restricted to the user or API key that submitted the search.

You can also use the scroll API to specify a new scroll parameter that extends or shortens the retention period for the search context.

IMPORTANT: Results from a scrolling search reflect the state of the index at the time of the initial search request. Subsequent indexing or document changes only affect later search and scroll requests.

Index

Constants

This section is empty.

Variables

View Source
var ErrBuildPath = errors.New("cannot build path, check for missing path parameters")

ErrBuildPath is returned in case of missing parameters within the build of the request.

Functions

This section is empty.

Types

type NewScroll

type NewScroll func() *Scroll

NewScroll type alias for index.

func NewScrollFunc

func NewScrollFunc(tp elastictransport.Interface) NewScroll

NewScrollFunc returns a new instance of Scroll with the provided transport. Used in the index of the library this allows to retrieve every apis in once place.

type Request

type Request struct {

	// Scroll The period to retain the search context for scrolling.
	Scroll types.Duration `json:"scroll,omitempty"`
	// ScrollId The scroll ID of the search.
	ScrollId string `json:"scroll_id"`
}

Request holds the request body struct for the package scroll

https://github.com/elastic/elasticsearch-specification/blob/52c473efb1fb5320a5bac12572d0b285882862fb/specification/_global/scroll/ScrollRequest.ts#L24-L88

func NewRequest

func NewRequest() *Request

NewRequest returns a Request

func (*Request) FromJSON

func (r *Request) FromJSON(data string) (*Request, error)

FromJSON allows to load an arbitrary json into the request structure

func (*Request) UnmarshalJSON

func (s *Request) UnmarshalJSON(data []byte) error

type Response

type Response struct {
	Aggregations map[string]types.Aggregate `json:"aggregations,omitempty"`
	Clusters_    *types.ClusterStatistics   `json:"_clusters,omitempty"`
	Fields       map[string]json.RawMessage `json:"fields,omitempty"`
	// Hits The returned documents and metadata.
	Hits            types.HitsMetadata `json:"hits"`
	MaxScore        *types.Float64     `json:"max_score,omitempty"`
	NumReducePhases *int64             `json:"num_reduce_phases,omitempty"`
	PitId           *string            `json:"pit_id,omitempty"`
	Profile         *types.Profile     `json:"profile,omitempty"`
	// ScrollId_ The identifier for the search and its search context.
	// You can use this scroll ID with the scroll API to retrieve the next batch of
	// search results for the request.
	// This property is returned only if the `scroll` query parameter is specified
	// in the request.
	ScrollId_ *string `json:"_scroll_id,omitempty"`
	// Shards_ A count of shards used for the request.
	Shards_         types.ShardStatistics      `json:"_shards"`
	Suggest         map[string][]types.Suggest `json:"suggest,omitempty"`
	TerminatedEarly *bool                      `json:"terminated_early,omitempty"`
	// TimedOut If `true`, the request timed out before completion; returned results may be
	// partial or empty.
	TimedOut bool `json:"timed_out"`
	// Took The number of milliseconds it took Elasticsearch to run the request.
	// This value is calculated by measuring the time elapsed between receipt of a
	// request on the coordinating node and the time at which the coordinating node
	// is ready to send the response.
	// It includes:
	//
	// * Communication time between the coordinating node and data nodes
	// * Time the request spends in the search thread pool, queued for execution
	// * Actual run time
	//
	// It does not include:
	//
	// * Time needed to send the request to Elasticsearch
	// * Time needed to serialize the JSON response
	// * Time needed to send the response to a client
	Took int64 `json:"took"`
}

Response holds the response body struct for the package scroll

https://github.com/elastic/elasticsearch-specification/blob/52c473efb1fb5320a5bac12572d0b285882862fb/specification/_global/scroll/ScrollResponse.ts#L22-L25

func NewResponse

func NewResponse() *Response

NewResponse returns a Response

func (*Response) UnmarshalJSON

func (s *Response) UnmarshalJSON(data []byte) error

type Scroll

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

func New

Run a scrolling search.

IMPORTANT: The scroll API is no longer recommend for deep pagination. If you need to preserve the index state while paging through more than 10,000 hits, use the `search_after` parameter with a point in time (PIT).

The scroll API gets large sets of results from a single scrolling search request. To get the necessary scroll ID, submit a search API request that includes an argument for the `scroll` query parameter. The `scroll` parameter indicates how long Elasticsearch should retain the search context for the request. The search response returns a scroll ID in the `_scroll_id` response body parameter. You can then use the scroll ID with the scroll API to retrieve the next batch of results for the request. If the Elasticsearch security features are enabled, the access to the results of a specific scroll ID is restricted to the user or API key that submitted the search.

You can also use the scroll API to specify a new scroll parameter that extends or shortens the retention period for the search context.

IMPORTANT: Results from a scrolling search reflect the state of the index at the time of the initial search request. Subsequent indexing or document changes only affect later search and scroll requests.

https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-scroll

func (Scroll) Do

func (r Scroll) Do(providedCtx context.Context) (*Response, error)

Do runs the request through the transport, handle the response and returns a scroll.Response

func (*Scroll) ErrorTrace

func (r *Scroll) ErrorTrace(errortrace bool) *Scroll

ErrorTrace When set to `true` Elasticsearch will include the full stack trace of errors when they occur. API name: error_trace

func (*Scroll) FilterPath

func (r *Scroll) FilterPath(filterpaths ...string) *Scroll

FilterPath Comma-separated list of filters in dot notation which reduce the response returned by Elasticsearch. API name: filter_path

func (*Scroll) Header

func (r *Scroll) Header(key, value string) *Scroll

Header set a key, value pair in the Scroll headers map.

func (*Scroll) HttpRequest

func (r *Scroll) HttpRequest(ctx context.Context) (*http.Request, error)

HttpRequest returns the http.Request object built from the given parameters.

func (*Scroll) Human

func (r *Scroll) Human(human bool) *Scroll

Human When set to `true` will return statistics in a format suitable for humans. For example `"exists_time": "1h"` for humans and `"eixsts_time_in_millis": 3600000` for computers. When disabled the human readable values will be omitted. This makes sense for responses being consumed only by machines. API name: human

func (Scroll) Perform

func (r Scroll) Perform(providedCtx context.Context) (*http.Response, error)

Perform runs the http.Request through the provided transport and returns an http.Response.

func (*Scroll) Pretty

func (r *Scroll) Pretty(pretty bool) *Scroll

Pretty If set to `true` the returned JSON will be "pretty-formatted". Only use this option for debugging only. API name: pretty

func (*Scroll) Raw

func (r *Scroll) Raw(raw io.Reader) *Scroll

Raw takes a json payload as input which is then passed to the http.Request If specified Raw takes precedence on Request method.

func (*Scroll) Request

func (r *Scroll) Request(req *Request) *Scroll

Request allows to set the request property with the appropriate payload.

func (*Scroll) RestTotalHitsAsInt

func (r *Scroll) RestTotalHitsAsInt(resttotalhitsasint bool) *Scroll

RestTotalHitsAsInt If true, the API response’s hit.total property is returned as an integer. If false, the API response’s hit.total property is returned as an object. API name: rest_total_hits_as_int

func (*Scroll) Scroll

func (r *Scroll) Scroll(duration types.DurationVariant) *Scroll

The period to retain the search context for scrolling. API name: scroll

func (*Scroll) ScrollId

func (r *Scroll) ScrollId(scrollid string) *Scroll

The scroll ID of the search. API name: scroll_id

Jump to

Keyboard shortcuts

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