Merge pull request #66 from navi-ppl/TP-5555/hotfix-search
TP-5555 | hotfix for search
This commit is contained in:
@@ -29,6 +29,7 @@ const (
|
||||
AggregationQuery = `"aggs": { %s }`
|
||||
AggregationQueryFormat = `"%s": { %s }` // aggregation name, aggregation query
|
||||
TermsAggregationQuery = `"terms": { "field": "%s", "size": %d, %s}`
|
||||
TermsAggregationQueryWithoutSort = `"terms": { "field": "%s", "size": %d}`
|
||||
MinAggregationQuery = `"min": { "field": "%s" }`
|
||||
MaxAggregationQuery = `"max": { "field": "%s" }`
|
||||
CardinalityAggregationQuery = `"cardinality": { "field": "%s" }`
|
||||
@@ -196,7 +197,11 @@ func CreateMaxAggregationQuery(field string) string {
|
||||
}
|
||||
|
||||
func CreateTermsAggregationQuery(field string, size int, orderQuery string) string {
|
||||
if len(orderQuery) > 0 {
|
||||
return fmt.Sprintf(TermsAggregationQuery, field, size, orderQuery)
|
||||
}
|
||||
return fmt.Sprintf(TermsAggregationQueryWithoutSort, field, size)
|
||||
|
||||
}
|
||||
|
||||
func CreateTermsAggregationQueryWithoutSize(field string) string {
|
||||
|
||||
@@ -128,9 +128,6 @@ func (s *SearchService) GetErrorListV2(c *gin.Context) {
|
||||
if sortKey == "count" {
|
||||
orderQuery = utils.CreateOrderQuery("_count", "desc")
|
||||
}
|
||||
if sortKey == "score" {
|
||||
orderQuery = utils.CreateOrderQuery("_score", "desc")
|
||||
}
|
||||
//size := c.DefaultQuery("size", "100000")
|
||||
term_query := utils.CreateTermSubQuery("project_id", projectId)
|
||||
multiMatchQuery := utils.CreateMultiMatchQuery(search_key, "error", "title", "extra.metadata.agentId",
|
||||
@@ -149,6 +146,10 @@ func (s *SearchService) GetErrorListV2(c *gin.Context) {
|
||||
first_seen_aggs_query := utils.BuildAggregationQuery("first_seen", utils.CreateMinAggregationQuery("created_at"))
|
||||
top_hits_aggs_query := utils.CreateAggregationQuery(top_hits_aggs_name_query, last_seen_aggs_query, first_seen_aggs_query)
|
||||
term_aggs_query := utils.CreateTermsAggregationQuery("error_hash", 100000, orderQuery)
|
||||
if sortKey == "score" {
|
||||
term_aggs_query = utils.CreateTermsAggregationQuery("error_hash", 100000, "")
|
||||
|
||||
}
|
||||
terms_aggs_query_with_name := utils.BuildAggregationQuery("errors_by_hash", term_aggs_query, top_hits_aggs_query)
|
||||
final_terms_aggs_query := utils.CreateAggregationQuery(terms_aggs_query_with_name)
|
||||
final_query := utils.CreateEsQuery(search_query, size_query, final_terms_aggs_query)
|
||||
|
||||
Reference in New Issue
Block a user