Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Creating a new Elasticsearch indexer instance

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content