thx for reply,
- only one field I want to use term aggs on
- It's a keyword type
about 1 to 2 million data i have to sort after terms aggs
e.g.
POST test_search_index/doc/_bulk
{"index":{"_id":"1"}}
{"name":"Michell","class":"A","age":26,"scoreA":99,"scoreB":100,"scoreC" : 99}
{"index":{"_id":"2"}}
{"name":"Job","class":"B","age":23,"scoreA":98,"scoreB":23,"scoreC" : 23}
{"index":{"_id":"3"}}
{"name":"mata","class":"C","age":21,"scoreA":97,"scoreB":44,"scoreC" : 54}
{"index":{"_id":"4"}}
{"name":"Bob","class":"C","age":20,"scoreA":97,"scoreB":55,"scoreC" : 65}
PUT test_search_index/_mapping/doc
{
"doc": {
"properties": {
"class": {
"type": "text",
"fielddata": true
}
}
}
}
GET test_search_index/_search
GET _cat/indices
A . terms aggs -> group by class , size = all (10000000)
B . top hits -> order by desc scoreA,scoreB,scoreC
C . bucket sort -> top hits and then order by desc scoreA,scoreB
and here is my query :
GET test_search_index/_search
{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"class": {
"terms": {
"field": "class",
"size": 5000000
},
"aggs": {
"SortGroup": {
"bucket_sort": {
"sort": [
{
"maxScoreA": "desc"
},
{
"maxScoreB": "desc"
}
],
"from": 0,
"size": 60
}
},
"maxScoreA": {
"max": {
"field": "scoreA"
}
},
"maxScoreB": {
"max": {
"field": "scoreB"
}
},
"SortWithinGroup": {
"top_hits": {
"sort": [
{
"scoreA": "desc"
},
{
"scoreB": "desc"
},
{
"scoreC": "desc"
}
],
"_source": {
"includes": [
"class",
"name",
"scoreA",
"scoreB",
"scoreC"
]
},
"size": 1
}
}
}
},
"count": {
"cardinality": {
"field": "goodsSn",
"precision_threshold": "40000"
}
}
}
}