reindex

package
v0.0.0-...-d8099e1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const IndexStoreSize = int64(100000000)

IndexStoreSize to decide whether to use async or sync re-indexing

Variables

View Source
var CurrentlyReIndexingProcess = make(map[string][]string)

CurrentlyReIndexingProcess map of taskID [source, destinations] indexes for which indexing process is going on

View Source
var CurrentlyReIndexingProcessMutex = sync.RWMutex{}

CurrentlyReIndexingProcessMutex to stop concurrent writes on map

Functions

func GetAliasIndexMap

func GetAliasIndexMap(ctx context.Context) (map[string]string, error)

func InitAliasIndexCache

func InitAliasIndexCache()

InitAliasIndexCache to set alias -> index cache on initialization

func InitIndexAliasCache

func InitIndexAliasCache()

InitIndexAliasCache to set cache on ReactiveSearch initialization

func IsReIndexInProcess

func IsReIndexInProcess(source, destination string) bool

IsReIndexInProcess check if index is Processing currently

func IsTaskCompleted

func IsTaskCompleted(ctx context.Context, taskID string) (bool, error)

To track a re-index task by taskID

func Reindex

func Reindex(ctx context.Context, sourceIndex string, config *ReindexConfig, waitForCompletion bool, destinationIndex string) ([]byte, error)

Reindex Inplace: https://www.elastic.co/guide/en/elasticsearch/reference/current/reindex-upgrade-inplace.html

  1. Create a new index and copy the mappings and settings from the old index.
  2. Set the refresh_interval to -1 and the number_of_replicas to 0 for efficient reindexing.
  3. Reindex all documents from the old index into the new index using the reindex API.
  4. Reset the refresh_interval and number_of_replicas to the values used in the old index.
  5. Wait for the index status to change to green.
  6. In a single update aliases request: a. Delete the old index. b. Add an alias with the old index name to the new index. c. Add any aliases that existed on the old index to the new index.

We accept a query param `wait_for_completion` which defaults to true, which when false, we don't create any aliases and delete the old index, we instead return the tasks API response.

func RemoveCurrentProcess

func RemoveCurrentProcess(taskID string)

RemoveCurrentProcess remove indexes for current reindexing process

func SetAlias

func SetAlias(aliasConfig SetAliasConfig) error

Set alias to an index

func SetCurrentProcess

func SetCurrentProcess(taskID, source, destination string)

SetCurrentProcess set indexes for current reindexing process

func TrackReindex

func TrackReindex(aliasConfig SetAliasConfig, taskDetails []byte)

To track reindex process. Use it in a go routine to track asynchronously.

Types

type Action

type Action int
const (
	Mappings Action = iota
	Settings
	Data
	SearchRelevancy
	Synonyms
)

func (Action) String

func (o Action) String() string

type AliasedIndices

type AliasedIndices struct {
	Alias        string      `json:"alias"`
	Health       string      `json:"health"`
	Status       string      `json:"status"`
	Index        string      `json:"index"`
	UUID         string      `json:"uuid"`
	Pri          interface{} `json:"pri"`
	Rep          interface{} `json:"rep"`
	DocsCount    interface{} `json:"docs.count"`
	DocsDeleted  interface{} `json:"docs.deleted"`
	StoreSize    string      `json:"store.size"`
	PriStoreSize string      `json:"pri.store.size"`
}

AliasedIndices struct

func GetAliasedIndices

func GetAliasedIndices(ctx context.Context) ([]AliasedIndices, error)

type ReIndexOperation

type ReIndexOperation int
const (
	ReIndexWithDelete ReIndexOperation = iota
	ReindexWithClone
)

func (ReIndexOperation) String

func (o ReIndexOperation) String() string

type ReindexConfig

type ReindexConfig struct {
	Mappings                map[string]interface{}  `json:"mappings"`
	Settings                map[string]interface{}  `json:"settings"`
	SearchRelevancySettings *map[string]interface{} `json:"search_relevancy_settings"`
	Include                 []string                `json:"include_fields"`
	Exclude                 []string                `json:"exclude_fields"`
	Types                   []string                `json:"types"`
	Action                  []string                `json:"action,omitempty"`
	Script                  string                  `json:"script"`
}

type SetAliasConfig

type SetAliasConfig struct {
	AliasName    string
	NewIndex     string
	OldIndex     string
	IsWriteIndex bool
}

type TaskResponseFailure

type TaskResponseFailure struct {
	Index  string `json:"index"`
	Type   string `json:"type"`
	ID     string `json:"id"`
	Status int32  `json:"status"`
	Cause  struct {
		Type     string `json:"type"`
		Reason   string `json:"reason"`
		CausedBy struct {
			Type   string `json:"type"`
			Reason string `json:"reason"`
		} `json:"caused_by"`
	} `json:"cause"`
}

type TaskResponseStruct

type TaskResponseStruct struct {
	Completed bool `json:"completed"`
	Response  struct {
		Failures []TaskResponseFailure `json:"failures"`
	} `json:"response"`
}

Jump to

Keyboard shortcuts

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