|
@@ -4,6 +4,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
es "github.com/olivere/elastic/v7"
|
|
|
+ "github.com/stretchr/testify/assert"
|
|
|
"testing"
|
|
|
)
|
|
|
|
|
@@ -40,7 +41,7 @@ func TestCount(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
fmt.Println("qqq", string(bytes))
|
|
|
- count1 := esClinet.Count("bidding", "", boolQuery)
|
|
|
+ count1 := esClinet.Count("bidding", boolQuery)
|
|
|
fmt.Println(count1)
|
|
|
}
|
|
|
|
|
@@ -70,3 +71,43 @@ func TestBulkSave(t *testing.T) {
|
|
|
esClinet.UpdateBulk("bidding", arru...)
|
|
|
fmt.Println(arru)
|
|
|
}
|
|
|
+
|
|
|
+func TestElastic_ExistsIndex(t *testing.T) {
|
|
|
+ esClinet = Elastic{
|
|
|
+ S_esurl: "http://127.0.0.1:19805",
|
|
|
+ I_size: 2,
|
|
|
+ Username: "es_all",
|
|
|
+ Password: "TopJkO2E_d1x",
|
|
|
+ }
|
|
|
+ esClinet.InitElasticSize()
|
|
|
+
|
|
|
+ res, err := esClinet.ExistsIndex("bidding_20231118")
|
|
|
+ assert.Equal(t, nil, err)
|
|
|
+ assert.Equal(t, true, res)
|
|
|
+}
|
|
|
+
|
|
|
+func TestElastic_SetAlias(t *testing.T) {
|
|
|
+ esClinet = Elastic{
|
|
|
+ S_esurl: "http://127.0.0.1:19805",
|
|
|
+ I_size: 2,
|
|
|
+ Username: "es_all",
|
|
|
+ Password: "TopJkO2E_d1x",
|
|
|
+ }
|
|
|
+ esClinet.InitElasticSize()
|
|
|
+
|
|
|
+ err := esClinet.SetAlias("bidding_20231118", "bidding_pre")
|
|
|
+ assert.Equal(t, nil, err)
|
|
|
+}
|
|
|
+
|
|
|
+func TestElastic_RemoveAlias(t *testing.T) {
|
|
|
+ esClinet = Elastic{
|
|
|
+ S_esurl: "http://127.0.0.1:19805",
|
|
|
+ I_size: 2,
|
|
|
+ Username: "es_all",
|
|
|
+ Password: "TopJkO2E_d1x",
|
|
|
+ }
|
|
|
+ esClinet.InitElasticSize()
|
|
|
+ err := esClinet.RemoveAlias("bidding_20231118", "bidding_pre")
|
|
|
+ assert.Equal(t, nil, err)
|
|
|
+
|
|
|
+}
|