-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery-duplicate-removal-data-for-es.go
105 lines (105 loc) · 2.83 KB
/
query-duplicate-removal-data-for-es.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
////从es的一个index中查询去重复的数据列表
package go_base_libs
//
//import (
// "context"
// "encoding/json"
// "time" //"gopkg.in/olivere/elastic.v6"
//
// "gopkg.in/olivere/elastic.v6"
//)
//
////var QueryDuplicateRemovalData = & queryDuplicateRemovalData{
//// Type: "log",
//// Size: 1000,
//// Aggregation: "groupby",
//// BucketsKeySlice: make([] string, 0),
////}
//
//func NewQueryDuplicateRemovalData() *queryDuplicateRemovalData {
// return &queryDuplicateRemovalData{
// Type: "log",
// Size: 1000,
// Aggregation: "groupby",
// BucketsKeySlice: make([]string, 0),
// }
//}
//
//type queryDuplicateRemovalData struct {
// IndexName string //必须
// FieldName string //必须
// Type string
// Aggregation string
// Size int
// BeginTime time.Duration
// EndTime time.Duration
// Res *elastic.SearchResult
// BucketsKeySlice []string
//}
//
//func (q *queryDuplicateRemovalData) SetIndexName(indexName string) *queryDuplicateRemovalData {
// q.IndexName = indexName
// return q
//}
//
//func (q *queryDuplicateRemovalData) SetFieldName(filedName string) *queryDuplicateRemovalData {
// q.FieldName = filedName
// return q
//}
//
//func (q *queryDuplicateRemovalData) SetType(docType string) *queryDuplicateRemovalData {
// q.Type = docType
// return q
//}
//
//func (q *queryDuplicateRemovalData) SetAggregation(aggregation string) *queryDuplicateRemovalData {
// q.Aggregation = aggregation
// return q
//}
//
//func (q *queryDuplicateRemovalData) SetSize(size int) *queryDuplicateRemovalData {
// q.Size = size
// return q
//}
//
//func (q *queryDuplicateRemovalData) QueryMain() (*queryDuplicateRemovalData, error) {
//
// OperateEs.User = "admin"
// OperateEs.Password = "1313GHGHG321dd"
// OperateEs.Address = "http://172.16.28.120:9200"
// OperateEs.initClient()
// esInitClient := elastic.NewTermsAggregation().Field(q.FieldName)
// res, err := OperateEs.Client.Search(q.IndexName).Type(q.Type).Size(q.Size).Aggregation(q.Aggregation, esInitClient).Do(context.Background())
// if err != nil {
// return q, err
// } else {
// q.Res = res
// }
//
// //解析数据
// var p AggregationsGroupby
// errJson := json.Unmarshal(*res.Aggregations["groupby"], &p)
// if errJson != nil {
// return q, errJson
// }
//
// // 有元素的时候,才开始轮训,把key存于一个动态的数组slice中
// if len(p.Buckets) > 0 {
// for _, v := range p.Buckets {
// q.BucketsKeySlice = append(q.BucketsKeySlice, v.Key)
// }
// }
//
// return q, nil
//}
//
//type AggregationsGroupby struct {
// DocCountErrorUpperBound int `json:"doc_count_error_upper_bound"`
// SumOtherDocCount int `json:"sum_other_doc_count"`
// Buckets []GroupbyBuckets
//}
//
//type GroupbyBuckets struct {
// Key string `json:"key"`
// DocCount int `json:"doc_count"`
//}