elastic使用包,基于olivere elastic v7
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1014 B

package elasticsearch
import (
"context"
"git.gz.internal.jumaiyx.cn/jm/jmproto/conf"
"git.gz.internal.jumaiyx.cn/pkg/log"
"testing"
)
func TestCreateIndex(t *testing.T) {
c := &conf.Elasticsearch{
Sniff: false,
Hosts: []string{"http://192.168.1.169:9200"},
Username: "elastic",
Password: "123456",
}
client, err := NewElastic(log.DefaultLogger(), c)
if err != nil {
panic(err)
}
type ElasticTest struct {
Name string `json:"name"`
}
body := ElasticTest{
Name: "测试",
}
// 创建索引
//_, err = client.CreateIndex("elastic_test").BodyJson(body).Do(context.Background())
//if err != nil {
// t.Fatal(err)
//}
_, err = client.Index().Index("elastic_test").BodyJson(body).Do(context.TODO())
if err != nil {
t.Fatal(err)
}
//Migrate([]interface{}{ElasticTest{}})
//u := ElasticTest{
// Name: "1212",
//}
//_, err = client.Index().Index("elastic_test").Id("id").BodyJson(u).Do(context.TODO())
//if err != nil {
// return
//}
//
//if err != nil {
//
//}
}