Skip to content

ugent-library/index

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Bulk indexing and index switching

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages