Browse Source

测试es的get请求

renzheng 7 năm trước cách đây
mục cha
commit
f78fe87d84
1 tập tin đã thay đổi với 16 bổ sung0 xóa
  1. 16 0
      common/src/qfw/util/elastic/elasticutil_Index_test.go

+ 16 - 0
common/src/qfw/util/elastic/elasticutil_Index_test.go

@@ -1,8 +1,10 @@
 package elastic
 
 import (
+	"encoding/json"
 	"log"
 	_ "log"
+	"net/url"
 
 	_ "gopkg.in/mgo.v2/bson"
 	_ "gopkg.in/olivere/elastic.v1"
@@ -81,3 +83,17 @@ func Test_saveToEs(t *testing.T) {
 		"title": "你好,试试2",
 	})
 }
+
+func Test_word(t *testing.T) {
+	InitElasticSize("http://192.168.3.207:9700", 2)
+	es := GetEsConn()
+	defer DestoryEsConn(es)
+	p := url.Values{}
+	p["text"] = []string{"中华人民共和国"}
+	p["analyzer"] = []string{"ik_pinyin"}
+	by, err := es.PerformRequest("GET", "/test1/_analyze", p, nil)
+	b, _ := by.Body.MarshalJSON()
+	var res map[string]interface{}
+	json.Unmarshal(b, &res)
+	log.Println(res, err)
+}