fixed a bug where when executing on a single shard and sorting terms agg based on sub metric agg, the order (asc/desc) is not respected
- fixed tests for terms order Closes #4951
This commit is contained in:
parent
4c06c533e8
commit
79d1633dd6
|
@ -215,7 +215,7 @@ class InternalOrder extends Terms.Order {
|
|||
if (v1 == Double.NaN) {
|
||||
return asc ? 1 : -1;
|
||||
}
|
||||
return Double.compare(v1, v2);
|
||||
return asc ? Double.compare(v1, v2) : Double.compare(v2, v1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ class InternalOrder extends Terms.Order {
|
|||
if (v1 == Double.NaN) {
|
||||
return asc ? 1 : -1;
|
||||
}
|
||||
return Double.compare(v1, v2);
|
||||
return asc ? Double.compare(v1, v2) : Double.compare(v2, v1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -820,14 +820,15 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(terms.getName(), equalTo("terms"));
|
||||
assertThat(terms.getBuckets().size(), equalTo(5));
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Terms.Bucket bucket = terms.getBucketByKey("val" + i);
|
||||
int i = 0;
|
||||
for (Terms.Bucket bucket : terms.getBuckets()) {
|
||||
assertThat(bucket, notNullValue());
|
||||
assertThat(key(bucket), equalTo("val" + i));
|
||||
assertThat(bucket.getDocCount(), equalTo(1l));
|
||||
Avg avg = bucket.getAggregations().get("avg_i");
|
||||
assertThat(avg, notNullValue());
|
||||
assertThat(avg.getValue(), equalTo((double) i));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -931,9 +932,8 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(terms.getName(), equalTo("terms"));
|
||||
assertThat(terms.getBuckets().size(), equalTo(5));
|
||||
|
||||
for (int i = 4; i >= 0; i--) {
|
||||
|
||||
Terms.Bucket bucket = terms.getBucketByKey("val" + i);
|
||||
int i = 4;
|
||||
for (Terms.Bucket bucket : terms.getBuckets()) {
|
||||
assertThat(bucket, notNullValue());
|
||||
assertThat(key(bucket), equalTo("val" + i));
|
||||
assertThat(bucket.getDocCount(), equalTo(1l));
|
||||
|
@ -941,6 +941,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
Avg avg = bucket.getAggregations().get("avg_i");
|
||||
assertThat(avg, notNullValue());
|
||||
assertThat(avg.getValue(), equalTo((double) i));
|
||||
i--;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -963,8 +964,8 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(terms.getName(), equalTo("terms"));
|
||||
assertThat(terms.getBuckets().size(), equalTo(5));
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Terms.Bucket bucket = terms.getBucketByKey("val" + i);
|
||||
int i = 0;
|
||||
for (Terms.Bucket bucket : terms.getBuckets()) {
|
||||
assertThat(bucket, notNullValue());
|
||||
assertThat(key(bucket), equalTo("val" + i));
|
||||
assertThat(bucket.getDocCount(), equalTo(1l));
|
||||
|
@ -972,6 +973,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
Stats stats = bucket.getAggregations().get("stats");
|
||||
assertThat(stats, notNullValue());
|
||||
assertThat(stats.getMax(), equalTo((double) i));
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -994,8 +996,8 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(terms.getName(), equalTo("terms"));
|
||||
assertThat(terms.getBuckets().size(), equalTo(5));
|
||||
|
||||
for (int i = 4; i >= 0; i--) {
|
||||
Terms.Bucket bucket = terms.getBucketByKey("val" + i);
|
||||
int i = 4;
|
||||
for (Terms.Bucket bucket : terms.getBuckets()) {
|
||||
assertThat(bucket, notNullValue());
|
||||
assertThat(key(bucket), equalTo("val" + i));
|
||||
assertThat(bucket.getDocCount(), equalTo(1l));
|
||||
|
@ -1003,6 +1005,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
Stats stats = bucket.getAggregations().get("stats");
|
||||
assertThat(stats, notNullValue());
|
||||
assertThat(stats.getMax(), equalTo((double) i));
|
||||
i--;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1014,7 +1017,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.variance", asc))
|
||||
.order(Terms.Order.aggregation("stats.sum_of_squares", asc))
|
||||
.subAggregation(extendedStats("stats").field("i"))
|
||||
).execute().actionGet();
|
||||
|
||||
|
@ -1025,8 +1028,8 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(terms.getName(), equalTo("terms"));
|
||||
assertThat(terms.getBuckets().size(), equalTo(5));
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Terms.Bucket bucket = terms.getBucketByKey("val" + i);
|
||||
int i = 0;
|
||||
for (Terms.Bucket bucket : terms.getBuckets()) {
|
||||
assertThat(bucket, notNullValue());
|
||||
assertThat(key(bucket), equalTo("val" + i));
|
||||
assertThat(bucket.getDocCount(), equalTo(1l));
|
||||
|
@ -1034,6 +1037,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
ExtendedStats stats = bucket.getAggregations().get("stats");
|
||||
assertThat(stats, notNullValue());
|
||||
assertThat(stats.getMax(), equalTo((double) i));
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue