Browse Source

feat:增加返回值

wangchuanjin 2 years ago
parent
commit
494efc26fe
2 changed files with 12 additions and 0 deletions
  1. 6 0
      es/esv1.go
  2. 6 0
      es/esv7.go

+ 6 - 0
es/esv1.go

@@ -1261,6 +1261,12 @@ func (e *EsV1) GetAggs(index, itype, query string) (aggs Aggregations, count int
 					if parseErr == nil && hit.Highlight != nil && res[i] != nil {
 						res[i]["highlight"] = map[string][]string(hit.Highlight)
 					}
+					if hit.Source != nil && res[i] != nil {
+						data := map[string]interface{}{}
+						dataByte, _ := hit.Source.MarshalJSON()
+						json.Unmarshal(dataByte, &data)
+						res[i]["source"] = data
+					}
 				}
 			} else {
 				log.Println("查询结果太多,查询到:", resNum, "条")

+ 6 - 0
es/esv7.go

@@ -1056,6 +1056,12 @@ func (e *EsV7) GetAggs(index, itype, query string) (aggs Aggregations, count int
 					if parseErr == nil && hit.Highlight != nil && res[i] != nil {
 						res[i]["highlight"] = map[string][]string(hit.Highlight)
 					}
+					if hit.Source != nil && res[i] != nil {
+						data := map[string]interface{}{}
+						dataByte, _ := hit.Source.MarshalJSON()
+						json.Unmarshal(dataByte, &data)
+						res[i]["source"] = data
+					}
 				}
 			} else {
 				log.Println("查询结果太多,查询到:", resNum, "条")