Thank you for your detailled answer.
But i'd really like to understand with adding score information on aggregation is so slow
This is profiling information
Aggregation with score
{
"category": {
"terms": {
"field": "category",
"size": 100
},
"aggs": {
"score": {
"max": {
"script": {
"lang": "painless",
"inline": "_score"
}
}
}
}
}
}
Profile result :
{
"type": "org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$WithHash",
"description": "category",
"time": "97.76644000ms",
"breakdown": {
"reduce": 0,
"build_aggregation": 90977021,
"build_aggregation_count": 1,
"initialize": 1760,
"initialize_count": 1,
"reduce_count": 0,
"collect": 6773280,
"collect_count": 14377
},
"children": [{
"type": "org.elasticsearch.search.aggregations.metrics.max.MaxAggregator",
"description": "score",
"time": "4.316251000ms",
"breakdown": {
"reduce": 0,
"build_aggregation": 5004,
"build_aggregation_count": 125,
"initialize": 315,
"initialize_count": 1,
"reduce_count": 0,
"collect": 4296429,
"collect_count": 14377
}
}]
}
Aggregation with field
{
"category": {
"terms": {
"field": "category",
"size": 100
},
"aggs": {
"score": {
"max": {
"field": "product_id"
}
}
}
}
}
Profile result :
{
"type": "org.elasticsearch.search.aggregations.bucket.terms.GlobalOrdinalsStringTermsAggregator$WithHash",
"description": "category",
"time": "6.224784000ms",
"breakdown": {
"reduce": 0,
"build_aggregation": 1436553,
"build_aggregation_count": 1,
"initialize": 1825,
"initialize_count": 1,
"reduce_count": 0,
"collect": 4771863,
"collect_count": 14541
},
"children": [{
"type": "org.elasticsearch.search.aggregations.metrics.max.MaxAggregator",
"description": "score",
"time": "0.4531270000ms",
"breakdown": {
"reduce": 0,
"build_aggregation": 7501,
"build_aggregation_count": 123,
"initialize": 298,
"initialize_count": 1,
"reduce_count": 0,
"collect": 430663,
"collect_count": 14541
}
}]
}