35 lines
643 B
Go
35 lines
643 B
Go
package controller
|
|
|
|
import (
|
|
"elasticstream/source/elastic"
|
|
|
|
"github.com/elastic/go-elasticsearch/v8"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
var client *elastic.Client
|
|
|
|
func Open(c *gin.Context) {
|
|
|
|
client = elastic.NewClient()
|
|
|
|
err := client.Configure(&Config{
|
|
Host: "http://test.urantiacloud.com:9200",
|
|
Indexes: []string{"index-a", "index-b", "index-c"},
|
|
BatchSize: 100,
|
|
DBPath: "index.db",
|
|
})
|
|
if err != nil {
|
|
c.Status(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
// Open connection with Elastic Search
|
|
err = client.Open()
|
|
if err != nil {
|
|
c.Status(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
c.Status(http.StatusOK)
|
|
}
|