@@ -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
|
||||
|
||||
Reference in New Issue
Block a user