January 2020
Intermediate to advanced
640 pages
16h 56m
English
To create a new Elasticsearch search indexer, clients need to invoke the NewElasticSearchIndexer constructor and provide a list of elastic search nodes to connect to. Our implementation will use the official Go client for Elasticsearch, which is provided by the go-elastic package [21]:
func NewElasticSearchIndexer(esNodes []string) (*ElasticSearchIndexer, error) { cfg := elasticsearch.Config{ Addresses: esNodes, } es, err := elasticsearch.NewClient(cfg) if err != nil { return nil, err } if err = ensureIndex(es); err != nil { return nil, err } return &ElasticSearchIndexer{ es: es, }, nil }
After creating a new go-elastic client, the constructor invokes the ensureIndex helper, which checks whether ...