rollover

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

Roll over to a new index. TIP: It is recommended to use the index lifecycle rollover action to automate rollovers.

The rollover API creates a new index for a data stream or index alias. The API behavior depends on the rollover target.

**Roll over a data stream**

If you roll over a data stream, the API creates a new write index for the stream. The stream's previous write index becomes a regular backing index. A rollover also increments the data stream's generation.

**Roll over an index alias with a write index**

TIP: Prior to Elasticsearch 7.9, you'd typically use an index alias with a write index to manage time series data. Data streams replace this functionality, require less maintenance, and automatically integrate with data tiers.

If an index alias points to multiple indices, one of the indices must be a write index. The rollover API creates a new write index for the alias with `is_write_index` set to `true`. The API also `sets is_write_index` to `false` for the previous write index.

**Roll over an index alias with one index**

If you roll over an index alias that points to only one index, the API creates a new index for the alias and removes the original index from the alias.

NOTE: A rollover creates a new index and is subject to the `wait_for_active_shards` setting.

**Increment index names for an alias**

When you roll over an index alias, you can specify a name for the new index. If you don't specify a name and the current index ends with `-` and a number, such as `my-index-000001` or `my-index-3`, the new index name increments that number. For example, if you roll over an alias with a current index of `my-index-000001`, the rollover creates a new index named `my-index-000002`. This number is always six characters and zero-padded, regardless of the previous index's name.

If you use an index alias for time series data, you can use date math in the index name to track the rollover date. For example, you can create an alias that points to an index named `<my-index-{now/d}-000001>`. If you create the index on May 6, 2099, the index's name is `my-index-2099.05.06-000001`. If you roll over the alias on May 7, 2099, the new index's name is `my-index-2099.05.07-000002`.

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 NewRollover

type NewRollover func(alias string) *Rollover

NewRollover type alias for index.

func NewRolloverFunc

func NewRolloverFunc(tp elastictransport.Interface) NewRollover

NewRolloverFunc returns a new instance of Rollover 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 {

	// Aliases Aliases for the target index.
	// Data streams do not support this parameter.
	Aliases map[string]types.Alias `json:"aliases,omitempty"`
	// Conditions Conditions for the rollover.
	// If specified, Elasticsearch only performs the rollover if the current index
	// satisfies these conditions.
	// If this parameter is not specified, Elasticsearch performs the rollover
	// unconditionally.
	// If conditions are specified, at least one of them must be a `max_*`
	// condition.
	// The index will rollover if any `max_*` condition is satisfied and all `min_*`
	// conditions are satisfied.
	Conditions *types.RolloverConditions `json:"conditions,omitempty"`
	// Mappings Mapping for fields in the index.
	// If specified, this mapping can include field names, field data types, and
	// mapping paramaters.
	Mappings *types.TypeMapping `json:"mappings,omitempty"`
	// Settings Configuration options for the index.
	// Data streams do not support this parameter.
	Settings map[string]json.RawMessage `json:"settings,omitempty"`
}

Request holds the request body struct for the package rollover

https://github.com/elastic/elasticsearch-specification/blob/52c473efb1fb5320a5bac12572d0b285882862fb/specification/indices/rollover/IndicesRolloverRequest.ts#L29-L153

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

type Response

type Response struct {
	Acknowledged       bool            `json:"acknowledged"`
	Conditions         map[string]bool `json:"conditions"`
	DryRun             bool            `json:"dry_run"`
	NewIndex           string          `json:"new_index"`
	OldIndex           string          `json:"old_index"`
	RolledOver         bool            `json:"rolled_over"`
	ShardsAcknowledged bool            `json:"shards_acknowledged"`
}

Response holds the response body struct for the package rollover

https://github.com/elastic/elasticsearch-specification/blob/52c473efb1fb5320a5bac12572d0b285882862fb/specification/indices/rollover/IndicesRolloverResponse.ts#L22-L32

func NewResponse

func NewResponse() *Response

NewResponse returns a Response

type Rollover

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

func New

Roll over to a new index. TIP: It is recommended to use the index lifecycle rollover action to automate rollovers.

The rollover API creates a new index for a data stream or index alias. The API behavior depends on the rollover target.

**Roll over a data stream**

If you roll over a data stream, the API creates a new write index for the stream. The stream's previous write index becomes a regular backing index. A rollover also increments the data stream's generation.

**Roll over an index alias with a write index**

TIP: Prior to Elasticsearch 7.9, you'd typically use an index alias with a write index to manage time series data. Data streams replace this functionality, require less maintenance, and automatically integrate with data tiers.

If an index alias points to multiple indices, one of the indices must be a write index. The rollover API creates a new write index for the alias with `is_write_index` set to `true`. The API also `sets is_write_index` to `false` for the previous write index.

**Roll over an index alias with one index**

If you roll over an index alias that points to only one index, the API creates a new index for the alias and removes the original index from the alias.

NOTE: A rollover creates a new index and is subject to the `wait_for_active_shards` setting.

**Increment index names for an alias**

When you roll over an index alias, you can specify a name for the new index. If you don't specify a name and the current index ends with `-` and a number, such as `my-index-000001` or `my-index-3`, the new index name increments that number. For example, if you roll over an alias with a current index of `my-index-000001`, the rollover creates a new index named `my-index-000002`. This number is always six characters and zero-padded, regardless of the previous index's name.

If you use an index alias for time series data, you can use date math in the index name to track the rollover date. For example, you can create an alias that points to an index named `<my-index-{now/d}-000001>`. If you create the index on May 6, 2099, the index's name is `my-index-2099.05.06-000001`. If you roll over the alias on May 7, 2099, the new index's name is `my-index-2099.05.07-000002`.

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

func (*Rollover) AddAlias

func (r *Rollover) AddAlias(key string, value types.AliasVariant) *Rollover

func (*Rollover) AddSetting

func (r *Rollover) AddSetting(key string, value json.RawMessage) *Rollover

func (*Rollover) Aliases

func (r *Rollover) Aliases(aliases map[string]types.Alias) *Rollover

Aliases for the target index. Data streams do not support this parameter. API name: aliases

func (*Rollover) Conditions

func (r *Rollover) Conditions(conditions types.RolloverConditionsVariant) *Rollover

Conditions for the rollover. If specified, Elasticsearch only performs the rollover if the current index satisfies these conditions. If this parameter is not specified, Elasticsearch performs the rollover unconditionally. If conditions are specified, at least one of them must be a `max_*` condition. The index will rollover if any `max_*` condition is satisfied and all `min_*` conditions are satisfied. API name: conditions

func (Rollover) Do

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

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

func (*Rollover) DryRun

func (r *Rollover) DryRun(dryrun bool) *Rollover

DryRun If `true`, checks whether the current index satisfies the specified conditions but does not perform a rollover. API name: dry_run

func (*Rollover) ErrorTrace

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

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

func (*Rollover) FilterPath

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

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

func (*Rollover) Header

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

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

func (*Rollover) HttpRequest

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

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

func (*Rollover) Human

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

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 (*Rollover) Lazy

func (r *Rollover) Lazy(lazy bool) *Rollover

Lazy If set to true, the rollover action will only mark a data stream to signal that it needs to be rolled over at the next write. Only allowed on data streams. API name: lazy

func (*Rollover) Mappings

func (r *Rollover) Mappings(mappings types.TypeMappingVariant) *Rollover

Mapping for fields in the index. If specified, this mapping can include field names, field data types, and mapping paramaters. API name: mappings

func (*Rollover) MasterTimeout

func (r *Rollover) MasterTimeout(duration string) *Rollover

MasterTimeout Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. API name: master_timeout

func (*Rollover) NewIndex

func (r *Rollover) NewIndex(newindex string) *Rollover

NewIndex Name of the index to create. Supports date math. Data streams do not support this parameter. API Name: newindex

func (Rollover) Perform

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

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

func (*Rollover) Pretty

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

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

func (*Rollover) Raw

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

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

func (*Rollover) Request

func (r *Rollover) Request(req *Request) *Rollover

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

func (*Rollover) Settings

func (r *Rollover) Settings(settings map[string]json.RawMessage) *Rollover

Configuration options for the index. Data streams do not support this parameter. API name: settings

func (*Rollover) Timeout

func (r *Rollover) Timeout(duration string) *Rollover

Timeout Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error. API name: timeout

func (*Rollover) WaitForActiveShards

func (r *Rollover) WaitForActiveShards(waitforactiveshards string) *Rollover

WaitForActiveShards The number of shard copies that must be active before proceeding with the operation. Set to all or any positive integer up to the total number of shards in the index (`number_of_replicas+1`). API name: wait_for_active_shards

Jump to

Keyboard shortcuts

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