feat(app): update
This commit is contained in:
@ -37,15 +37,15 @@ type User struct {
|
||||
WellNoIcon string
|
||||
}
|
||||
|
||||
//字符串: text keyword
|
||||
//整数 : byte, short, integer, long
|
||||
//浮点数: float, double
|
||||
//布尔型: boolean
|
||||
//日期: date
|
||||
var UserIndex = map[string]interface{}{
|
||||
"settings": map[string]interface{}{"number_of_shards": 5, "number_of_replicas": 1},
|
||||
"mappings": map[string]interface{}{
|
||||
"properties": map[string]interface{}{
|
||||
// 字符串: text keyword
|
||||
// 整数 : byte, short, integer, long
|
||||
// 浮点数: float, double
|
||||
// 布尔型: boolean
|
||||
// 日期: date
|
||||
var UserIndex = map[string]any{
|
||||
"settings": map[string]any{"number_of_shards": 5, "number_of_replicas": 1},
|
||||
"mappings": map[string]any{
|
||||
"properties": map[string]any{
|
||||
"ActiveTime": map[string]string{"type": "date", "format": "yyyy-MM-dd HH:mm:ssZ||yyyy-MM-dd HH:mm:ss.SSSZ||yyyy-MM-ddZ||epoch_millis||epoch_second"},
|
||||
"AlipayAccount": map[string]string{"type": "keyword"},
|
||||
"AuthFailReason": map[string]string{"type": "text", "analyzer": "ik_max_word"},
|
||||
@ -83,10 +83,10 @@ var UserIndex = map[string]interface{}{
|
||||
},
|
||||
}
|
||||
|
||||
var MessageIndex = map[string]interface{}{
|
||||
"settings": map[string]interface{}{"number_of_shards": 5, "number_of_replicas": 1},
|
||||
"mappings": map[string]interface{}{
|
||||
"properties": map[string]interface{}{
|
||||
var MessageIndex = map[string]any{
|
||||
"settings": map[string]any{"number_of_shards": 5, "number_of_replicas": 1},
|
||||
"mappings": map[string]any{
|
||||
"properties": map[string]any{
|
||||
"id": map[string]string{"type": "keyword"},
|
||||
"curTime": map[string]string{"type": "date", "format": "yyyy-MM-dd HH:mm:ssZ||yyyy-MM-dd HH:mm:ss.SSSZ||yyyy-MM-ddZ||epoch_millis||epoch_second"},
|
||||
},
|
||||
|
||||
@ -70,7 +70,7 @@ func _connect() (c *elastic.Client) {
|
||||
}
|
||||
|
||||
// 创建记录
|
||||
func (*EsClient) Create(index, id string, model interface{}) (body string, success bool, msg string) {
|
||||
func (*EsClient) Create(index, id string, model any) (body string, success bool, msg string) {
|
||||
client := _connect()
|
||||
_, e := client.Index().Index(index).Id(id).BodyJson(model).Do(context.Background())
|
||||
if e != nil {
|
||||
@ -99,7 +99,7 @@ func (*EsClient) Exists(index, id string) (exists, success bool, msg string, e e
|
||||
}
|
||||
|
||||
// 更新记录
|
||||
func (*EsClient) Update(index, id string, model interface{}) (body string, success bool, msg string) {
|
||||
func (*EsClient) Update(index, id string, model any) (body string, success bool, msg string) {
|
||||
client := _connect()
|
||||
_, e := client.Update().Index(index).Id(id).Doc(model).Do(context.Background())
|
||||
if e != nil {
|
||||
@ -112,7 +112,7 @@ func (*EsClient) Update(index, id string, model interface{}) (body string, succe
|
||||
}
|
||||
|
||||
// 搜索
|
||||
func (*EsClient) Search(index string, key string, fields ...string) (body []interface{}, success bool, msg string) {
|
||||
func (*EsClient) Search(index string, key string, fields ...string) (body []any, success bool, msg string) {
|
||||
client := _connect()
|
||||
logs.Info("ES Search index =", index, " key =", key, " fields =", fields)
|
||||
var list []*elastic.WildcardQuery
|
||||
@ -165,7 +165,7 @@ type ESSort struct {
|
||||
}
|
||||
|
||||
// 搜索消息
|
||||
func (*EsClient) SearchMulti(index string, filter ESFilter, page, size int) (result interface{}, success bool, msg string) {
|
||||
func (*EsClient) SearchMulti(index string, filter ESFilter, page, size int) (result any, success bool, msg string) {
|
||||
client := _connect()
|
||||
var list []elastic.Query
|
||||
for _, item := range filter.Queries {
|
||||
@ -217,14 +217,14 @@ func (*EsClient) SearchMulti(index string, filter ESFilter, page, size int) (res
|
||||
if e != nil {
|
||||
return
|
||||
}
|
||||
var body []interface{}
|
||||
var body []any
|
||||
for _, item := range res.Hits.Hits {
|
||||
b, _ := item.Source.MarshalJSON()
|
||||
m := make(map[string]interface{})
|
||||
m := make(map[string]any)
|
||||
_ = json.Unmarshal(b, &m)
|
||||
body = append(body, m)
|
||||
}
|
||||
result = map[string]interface{}{
|
||||
result = map[string]any{
|
||||
"Status": res.Status,
|
||||
"Total": res.Hits.TotalHits,
|
||||
"List": body,
|
||||
|
||||
@ -45,7 +45,7 @@ func _testConnect() (c *elastic.Client) {
|
||||
|
||||
func TestClientNew(t *testing.T) {
|
||||
var client EsClient
|
||||
client.Create("es_index_message", "003", map[string]interface{}{
|
||||
client.Create("es_index_message", "003", map[string]any{
|
||||
"id": "003",
|
||||
"curTime": 1440570500855,
|
||||
"f1": 1234,
|
||||
|
||||
Reference in New Issue
Block a user