comment-1

Signed-off-by: huanggze <loganhuang@yunify.com>
This commit is contained in:
huanggze
2019-08-21 15:57:52 +08:00
parent bfed3a6baa
commit 429573c837
5 changed files with 31 additions and 27 deletions

View File

@@ -10,24 +10,25 @@ import (
)
type Elastic struct {
Client *elasticsearch.Client
client *elasticsearch.Client
index string
}
func New(address string) Elastic {
func New(address string, index string) Elastic {
client, _ := elasticsearch.NewClient(elasticsearch.Config{
Addresses: []string{address},
})
return Elastic{Client: client}
return Elastic{client: client, index: index}
}
func (e Elastic) Search(body []byte, indexPrefix string) ([]byte, error) {
func (e Elastic) Search(body []byte) ([]byte, error) {
response, err := e.Client.Search(
e.Client.Search.WithContext(context.Background()),
e.Client.Search.WithIndex(fmt.Sprintf("%s*", indexPrefix)),
e.Client.Search.WithBody(bytes.NewBuffer(body)),
response, err := e.client.Search(
e.client.Search.WithContext(context.Background()),
e.client.Search.WithIndex(fmt.Sprintf("%s*", e.index)),
e.client.Search.WithBody(bytes.NewBuffer(body)),
)
if err != nil {
return nil, err