Commit e7aace7e by 姚冰

[chg] 聚合添加排序

1 parent 3a0dd477
......@@ -529,9 +529,10 @@ public class PersonService {
// personIdAgg.size(matchResultSize);
// builder.aggregation(personIdAgg);
Script script = new Script.Builder().source("_score").build();
Aggregation maxAgg = AggregationBuilders.max(f -> f.field("_score").script(script));
Aggregation maxAgg = AggregationBuilders.max(f -> f.script(script));
NamedValue<SortOrder> sortOrder = NamedValue.of("max_score", SortOrder.Desc);
Aggregation termsAgg = new Aggregation.Builder()
.terms(t -> t.field("personId").size(matchResultSize))
.terms(t -> t.field("personId").size(matchResultSize).order(sortOrder))
.aggregations("max_score", maxAgg)
.build();
searchRequest.aggregations("by_personId", termsAgg).size(0);
......@@ -570,7 +571,7 @@ public class PersonService {
for (StringTermsBucket bucket : byPersonId.buckets().array()) {
String personId = bucket.key().stringValue();
MaxAggregate maxAggregate = (MaxAggregate) bucket.aggregations().get("max_score")._get();
double value = maxAggregate.value();
double value = maxAggregate.value() * 100;
Person person = new Person().setPersonId(personId).setScore((float) value).setPersonPoolId(poolId);
persons.add(person);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!