wangchuanjin пре 1 година
родитељ
комит
5004df4803
2 измењених фајлова са 44 додато и 0 уклоњено
  1. 3 0
      esv7/elasticutil.go
  2. 41 0
      esv7/es_test.go

+ 3 - 0
esv7/elasticutil.go

@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"log"
 	"reflect"
+	"regexp"
 	"runtime"
 	"strconv"
 	"strings"
@@ -33,6 +34,7 @@ var pool chan *es.Client
 var ntimeout int
 
 var syncPool sync.Pool
+var filterReg = regexp.MustCompile(`,\s*"should"\s*:\s*\[\s*\]\s*,\s*"minimum_should_match"\s*:\s*1`)
 
 //初始化全文检索
 func InitElastic(addr string) {
@@ -192,6 +194,7 @@ func Get(index, itype, query string) *[]map[string]interface{} {
 	return r
 }
 func get(index, itype, searchType, query string, isLimit, isHighlight bool) (int64, int, *[]map[string]interface{}) {
+	query = filterReg.ReplaceAllString(query, "")
 	//log.Println("query  -- ", query)
 	client := GetEsConn()
 	defer func() {

+ 41 - 0
esv7/es_test.go

@@ -0,0 +1,41 @@
+package elastic
+
+import (
+	"log"
+	"testing"
+)
+
+type AggregationsBucket struct {
+	Key       string `json:"key"`
+	Doc_count int    `json:"doc_count"`
+	Count     struct {
+		Value float64 `json:value`
+	} `json:"count"`
+}
+
+func TestGet(t *testing.T) {
+	q := `{
+	  "query": {
+	    "bool": {
+	      "must": [
+	        {
+	          "term": {
+	            "id": "64e6b70abc72bfca100f4b63"
+	          }
+	        }
+	      ]
+	    }
+	  }
+	}`
+	NewEs("v7", "http://127.0.0.1:19805", 2, "elastic", "MsOCrY7Yct3sjVvB5gCd")
+	//NewEs("v1", "http://192.168.3.206:9800", 2, "", "")
+	list := Get("bidding", "bidding", q)
+	log.Println(list)
+}
+
+func TestAnalyze(t *testing.T) {
+	NewEs("v7", "http://192.168.3.241:9205,http://192.168.3.149:9200", 2, "", "")
+	//NewEs("v1", "http://192.168.3.206:9800", 2, "", "")
+	res := Analyze("软件中国", "bidding", "ik_smart")
+	log.Println(res)
+}