Skip to content

Instantly share code, notes, and snippets.

@zryfish
Created September 4, 2019 10:59
Show Gist options
  • Select an option

  • Save zryfish/b91376c4aa265e1cf59aa02e045c4b17 to your computer and use it in GitHub Desktop.

Select an option

Save zryfish/b91376c4aa265e1cf59aa02e045c4b17 to your computer and use it in GitHub Desktop.
import (
"fmt"
esv5 "github.com/elastic/go-elasticsearch/v5"
esv6 "github.com/elastic/go-elasticsearch/v6"
esv7 "github.com/elastic/go-elasticsearch/v7"
)
type ES_VERSION string
const (
V5 ES_VERSION = "v5"
V6 ES_VERSION = "v6"
V7 ES_VERSION = "v7"
)
type Client interface {
// Perform Search API
Search(body []byte) ([]byte, error)
GetTotalHitCount(v interface{}) int64
}
type ElasticClient struct {
v5 *esv5.Client
v6 *esv6.Client
v7 *esv7.Client
index string
version ES_VERSION
}
func NewElasticClient(address, index string, version ES_VERSION) *ElasticClient {
es := &ElasticClient{
version: version,
index: index,
}
var err error
switch es.version {
case V5:
es.v5, err = esv5.NewClient(esv5.Config{
Addresses: []string{address},
})
if err != nil {
}
case V6:
es.v6, err = esv6.NewClient(esv6.Config{
Addresses: []string{address},
})
case V7:
es.v7, err = esv7.NewClient(esv7.Config{
Addresses: []string{address},
})
default:
}
return es
}
func (e *ElasticClient) Search(body []byte) ([]byte, error) {
return []byte{}, nil
}
func (e *ElasticClient) GetTotalHit(v interface{}) int64 {
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment