From 8d287b1d7bfa6e83a639c28451665aa37518311c Mon Sep 17 00:00:00 2001 From: Pradeep Mishra Date: Fri, 21 Oct 2016 12:43:26 +0200 Subject: [PATCH] Added ES SimpleClient support for annotations backend --- backend/backend.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/backend/backend.go b/backend/backend.go index 85f0a38..83f4d7c 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -25,14 +25,15 @@ const docType = "annotation" type Elastic struct { *elastic.Client - index string - urls []string - maxResults int - initialized bool + index string + urls []string + simpleClient bool + maxResults int + initialized bool } -func NewElastic(urls []string, index string) *Elastic { - return &Elastic{&elastic.Client{}, index, urls, 200, false} +func NewElastic(urls []string, simpleclient bool, index string) *Elastic { + return &Elastic{&elastic.Client{}, index, urls, simpleclient, 200, false} } var unInitErr = fmt.Errorf("backend has not been initialized") @@ -172,7 +173,15 @@ func (e *Elastic) GetFieldValues(field string) ([]string, error) { } func (e *Elastic) InitBackend() error { - ec, err := elastic.NewClient(elastic.SetURL(e.urls...)) + var err error + var ec *elastic.Client + + if e.simpleClient { + ec, err = elastic.NewSimpleClient(elastic.SetURL(e.urls...)) + } else { + ec, err = elastic.NewClient(elastic.SetURL(e.urls...)) + } + if err != nil { return err }