TP-55555 | fix es query for pagination
This commit is contained in:
@@ -43,8 +43,10 @@ const (
|
||||
MatchQuery = `{ "match": { "%s": "%s" } }`
|
||||
SearchAfter = `"search_after": [%s]`
|
||||
CompositeAggsQuery = `"composite": {"size" : %d, "sources" : [{"%s": {%s}}] }`
|
||||
TopHitsAggsQuery = `"top_hits":{"_source": {"includes" : ["%s"]}}`
|
||||
ValueCountAggsQuery = `"value_count" : {"field": "%s"}`
|
||||
CompositeAggsQueryWithAfterKey = `"composite": {"size" : %d, "after": {"%s": "%s"}, "sources" : [{"%s": {%s}}] }`
|
||||
|
||||
TopHitsAggsQuery = `"top_hits":{"size" : %d, "_source": {"includes" : [ %s ]}}`
|
||||
ValueCountAggsQuery = `"value_count" : {"field": "%s"}`
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -234,12 +236,21 @@ func CreateSearchAfterQuery(searchQuery ...string) string {
|
||||
return fmt.Sprintf(SearchAfter, strings.Join(searchQuery, ","))
|
||||
}
|
||||
|
||||
func CreateCompositeAggsQuery(size int, key string, sources ...string) string {
|
||||
func CreateCompositeAggsQuery(size int, key string, afterKey string, afterKeyValue string, sources ...string) string {
|
||||
if afterKeyValue != EMPTY {
|
||||
println("in after key query")
|
||||
return fmt.Sprintf(CompositeAggsQueryWithAfterKey, size, afterKey, afterKeyValue, key, strings.Join(sources, ","))
|
||||
|
||||
}
|
||||
return fmt.Sprintf(CompositeAggsQuery, size, key, strings.Join(sources, ","))
|
||||
}
|
||||
|
||||
func CreateTopHitsAggsQuery(fields ...string) string {
|
||||
return fmt.Sprintf(TopHitsAggsQuery, strings.Join(fields, ","))
|
||||
func CreateTopHitsAggsQuery(size int, fields []string) string {
|
||||
var fieldsList []string
|
||||
for _, field := range fields {
|
||||
fieldsList = append(fieldsList, fmt.Sprintf(`"%s"`, field))
|
||||
}
|
||||
return fmt.Sprintf(TopHitsAggsQuery, size, strings.Join(fieldsList, ", "))
|
||||
}
|
||||
|
||||
func CreateValueCountAggsQuery(field string) string {
|
||||
|
||||
Reference in New Issue
Block a user