TP-55555 | change elastic query to builder queries
This commit is contained in:
@@ -6,10 +6,9 @@ import (
|
||||
"cybertron/configs"
|
||||
"encoding/json"
|
||||
elasticsearch8 "github.com/elastic/go-elasticsearch/v8"
|
||||
"github.com/elastic/go-elasticsearch/v8/typedapi/core/search"
|
||||
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ElasticSearchClient struct {
|
||||
@@ -45,12 +44,9 @@ func (el *ElasticSearchClient) IndexDocument(document interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (el *ElasticSearchClient) SearchDocuments(query *types.Query, fields []string) ([]map[string]interface{}, error) {
|
||||
func (el *ElasticSearchClient) SearchDocuments(searchRequest string, fields []string) ([]map[string]interface{}, map[string]interface{}, error) {
|
||||
res, err := el.client.Search().
|
||||
Index(el.Config.Index).
|
||||
Request(&search.Request{
|
||||
Query: query,
|
||||
}).Source_(fields).
|
||||
Index(el.Config.Index).Raw(strings.NewReader(searchRequest)).
|
||||
Do(context.TODO())
|
||||
if err != nil {
|
||||
log.Println("Error getting response: %s", err)
|
||||
@@ -67,8 +63,16 @@ func (el *ElasticSearchClient) SearchDocuments(query *types.Query, fields []stri
|
||||
}
|
||||
results = append(results, doc)
|
||||
}
|
||||
aggregations := make(map[string]interface{})
|
||||
if res.Aggregations != nil {
|
||||
for aggName, agg := range res.Aggregations {
|
||||
aggregations[aggName] = agg
|
||||
}
|
||||
}
|
||||
|
||||
return results, nil
|
||||
log.Printf("%s", aggregations)
|
||||
|
||||
return results, aggregations, nil
|
||||
}
|
||||
|
||||
func (el *ElasticSearchClient) GetDocument(documentID string) (interface{}, error) {
|
||||
|
||||
Reference in New Issue
Block a user