123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package elastic
- import (
- "encoding/json"
- "log"
- _ "log"
- "net/url"
- _ "gopkg.in/mgo.v2/bson"
- _ "sfbase/olivere/elastic.v1"
- "qfw/util/mongodb"
- "testing"
- )
- func Test_DelIndex(t *testing.T) {
- InitElastic("http://192.168.3.14:9800")
- client := GetEsConn()
- client.DeleteIndex("zcfg_v1").Do()
- //client.c("qfw", "qfw2").Do()
- //l1 := time.Now().Unix()
- //log.Println(util.LongToDate(l1, true))
- DestoryEsConn(client)
- }
- func Test_createMapping(t *testing.T) {
- InitElastic("http://192.168.3.14:9800")
- client := GetEsConn()
- //client.DeleteIndex("qfw").Do()
- var testMapping = `{"mappings":{
- "enterprise":{
- "_id" : {
- "path" : "_id"
- },
- "properties":{
- "EntName" : {
- "type" : "string",
- "analyzer" : "ik"
- }
- }
- }
- }
- }`
- _ = testMapping
- createIndex2, err := client.CreateIndex("qfw2").Do()
- log.Println(createIndex2, err.Error())
- DestoryEsConn(client)
- }
- func Test_saveMongodbToEs(t *testing.T) {
- mongodb.InitMongodbPool(1, "192.168.3.14:27080", "qfw")
- InitElastic("http://192.168.3.14:9800")
- res := mongodb.Find("content", `{}`, nil, nil, false, -1, -1)
- log.Println(len(*res))
- BulkSave("content_v2", "content", res, false)
- }
- func Test_saveContentMongodbToEs(t *testing.T) {
- mongodb.InitMongodbPool(1, "192.168.3.18:27080", "qfw")
- InitElastic("http://192.168.3.18:9800")
- res := mongodb.Find("enterprise", `{}`, nil, nil, false, -1, -1)
- log.Println(len(*res))
- BulkSave("enterprise", "enterprise", res, false)
- }
- func Test_find1(t *testing.T) {
- InitElastic("http://192.168.3.14:9800")
- log.Println(GetPage("qfw_back", "enterprise", `{"RegOrgName":"中心"}`, "", `"RegOrgName"`, 1, 2))
- }
- func Test_Convert(t *testing.T) {
- mongodb.InitMongodbPool(1, "192.168.3.14:27080", "qfw")
- //InitElastic("http://192.168.3.14:9800")
- log.Println(ConverData(mongodb.FindOne("enterprise", `{"_id":"556db9f0c2e8753072b52ee9"}`)))
- }
- func Test_saveToEs(t *testing.T) {
- InitElasticSize("http://192.168.3.18:9800", 2)
- Save("bidlibrary", "bidlibrary", map[string]interface{}{
- "_id": "556db9f0c2e8753072b52ee5",
- "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"}
- 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)
- }
|