diff --git a/config.go b/config.go index d0abdef..996f49e 100644 --- a/config.go +++ b/config.go @@ -2,6 +2,7 @@ package elasticsearch import "github.com/Selly-Modules/natsio" +// Config int client elasticsearch type Config struct { ApiKey string Nats natsio.Config diff --git a/constants.go b/constants.go index 9dc6c8f..f3018b0 100644 --- a/constants.go +++ b/constants.go @@ -1,5 +1,5 @@ package elasticsearch -const SubjectSyncData = "sync_data" -const SubjectSearch = "search" -const SubjectUpdateDocument = "update_document" +const SubjectSyncData = "elasticsearch_sync_data" +const SubjectSearch = "elasticsearch_search" +const SubjectUpdateDocument = "elasticsearch_update_document" diff --git a/elasticsearch.go b/elasticsearch.go index f0dbcee..eb32160 100644 --- a/elasticsearch.go +++ b/elasticsearch.go @@ -8,12 +8,15 @@ import ( "github.com/Selly-Modules/natsio" ) +// Client ... type Client struct { Config Config natsServer natsio.Server natsJetStream natsio.JetStream } +// NewClient +// Init client elasticsearch func NewClient(config Config) (*Client, error) { if config.ApiKey == "" { return nil, errors.New("api key is required") @@ -34,6 +37,8 @@ func NewClient(config Config) (*Client, error) { return c, nil } +// SyncData +// Sync data to services ES func (c *Client) SyncData(data SyncData) (bool, error) { var ( res Response @@ -51,6 +56,8 @@ func (c *Client) SyncData(data SyncData) (bool, error) { return res.Success, nil } +// Search +// Request search to service es func (c *Client) Search(query ESQuery) ([]string, error) { var ( res Response @@ -68,6 +75,8 @@ func (c *Client) Search(query ESQuery) ([]string, error) { return res.Data, nil } +// UpdateDocument +// Insert or update document to ES func (c *Client) UpdateDocument(query UpdateDataPayload) ([]string, error) { var ( res Response diff --git a/struct.go b/struct.go index 05ec9e1..38a0519 100644 --- a/struct.go +++ b/struct.go @@ -2,6 +2,8 @@ package elasticsearch import "time" +// Response +// response to service es type Response struct { Success bool `json:"success"` Data []string `json:"data,omitempty"` @@ -11,16 +13,22 @@ type Response struct { Message string `json:"message"` } +// SyncData +// Payload for sync data to service es type SyncData struct { Index string Data []byte } +// UpdateDataPayload +// Payload for insert or update document type UpdateDataPayload struct { Index string Body []byte } +// ESQuery +// Query support to search document type ESQuery struct { Index string // Index Page int64 @@ -73,7 +81,11 @@ type ESQuery struct { Segments []string } +// ESSort +// ES sort with field +// ... filed is sort +// ... ascending [true is asc] [false is desc] type ESSort struct { - Filed string // Filed sort + Field string // Filed sort Ascending bool }