feat:优化es查询规则
This commit is contained in:
@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/olivere/elastic/v7"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@ -22,17 +21,20 @@ type Student struct {
|
||||
AverageScore float64 `json:"average_score"`
|
||||
}
|
||||
|
||||
func TestNewInstance(t *testing.T) {
|
||||
func _new() *elastic.Client {
|
||||
client, err := elastic.NewClient(elastic.SetSniff(false), elastic.SetURL(host))
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if _, _, err = client.Ping(host).Do(context.Background()); err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
func TestNewInstance(t *testing.T) {
|
||||
client := _new()
|
||||
|
||||
//newStudent := Student{
|
||||
// Name: "熊,桥,顺",
|
||||
@ -92,44 +94,21 @@ func TestNewInstance1(t *testing.T) {
|
||||
//t.Log(resp)
|
||||
}
|
||||
|
||||
type Manage struct {
|
||||
ID uint64 `json:"id"`
|
||||
}
|
||||
|
||||
func TestNewInstance2(t *testing.T) {
|
||||
//NewInstance(
|
||||
// WithEsAddress([]string{"http://192.168.0.188:9200"}),
|
||||
//).Init().Local()
|
||||
client := _new()
|
||||
|
||||
//client.Search(func(request *esapi.SearchRequest) {
|
||||
//
|
||||
//})
|
||||
query := elastic.NewBoolQuery()
|
||||
query.Must(elastic.NewMatchQuery("title", "一种"))
|
||||
query.Must(elastic.NewMatchPhraseQuery("industry", "你是"))
|
||||
|
||||
function := func(src interface{}) {
|
||||
obj := reflect.ValueOf(src).Interface()
|
||||
t.Log(obj)
|
||||
var a interface{} = &Manage{ID: 123123}
|
||||
service := client.Search().Index("es_patent_index")
|
||||
|
||||
out := make([]interface{}, 0)
|
||||
|
||||
out = append(out, a)
|
||||
result, err := service.Pretty(true).Query(query).Do(context.Background())
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
manage := new(Manage)
|
||||
|
||||
function(manage)
|
||||
|
||||
var a interface{} = &Manage{ID: 123123}
|
||||
|
||||
out := make([]interface{}, 0)
|
||||
|
||||
out = append(out, a)
|
||||
|
||||
t.Log(reflect.TypeOf(manage))
|
||||
|
||||
for _, v := range out {
|
||||
t.Log(v.(*Manage))
|
||||
for _, v := range result.Hits.Hits {
|
||||
t.Log(string(v.Source))
|
||||
}
|
||||
t.Log(a)
|
||||
}
|
||||
|
Reference in New Issue
Block a user