Categorygithub.com/ugent-library/index
module
0.0.0-20240208101504-240e390f8d3d
Repository: https://github.com/ugent-library/index.git
Documentation: pkg.go.dev

# README

index

Bulk indexing and index switching

How to use

package main

import (
	"context"
	"log"

	"github.com/elastic/go-elasticsearch/v6"
	"github.com/ugent-library/index/es6"
)

func main() {
	client, err := elasticsearch.NewClient(elasticsearch.Config{
		Addresses: []string{"address"},
	})

	if err != nil {
		log.Println("error")
	}

	// Create a new switcher, auto-create a new index
	switcher, err := index.NewSwitcher(client, "my-index", "{...}")

	if err != nil {
		log.Println("error")
	}

	// Create a new indexer for the newly created index
	name := switcher.Name()
	indexer, err := index.NewIndexer(client, name, index.IndexerConfig{})

	if err != nil {
		log.Println("error")
	}

	// Add a doc to the new index
	ctx := context.Background()
	id := "id"
	doc := []byte("{...}")
	indexer.Index(ctx, id, doc)
	indexer.Close(ctx)

	// Switch the alias over to the new index
	switcher.Switch(ctx, 5)
}

# Packages

No description provided by the author