index

module
v0.0.0-...-240e390 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: Apache-2.0

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)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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