Merge pull request #15393 from jimferenczi/terms_agg_getKeyAsString

getKeyAsString and key_as_string should be the same for terms aggregation.
This commit is contained in:
Jim Ferenczi 2015-12-15 12:11:23 +01:00
commit 715528a567
3 changed files with 13 additions and 9 deletions

View File

@ -91,7 +91,7 @@ public class LongTerms extends InternalTerms<LongTerms, LongTerms.Bucket> {
@Override @Override
public String getKeyAsString() { public String getKeyAsString() {
return String.valueOf(term); return formatter.format(term);
} }
@Override @Override

View File

@ -99,20 +99,22 @@ public class BooleanTermsIT extends ESIntegTestCase {
final int bucketCount = numSingleFalses > 0 && numSingleTrues > 0 ? 2 : numSingleFalses + numSingleTrues > 0 ? 1 : 0; final int bucketCount = numSingleFalses > 0 && numSingleTrues > 0 ? 2 : numSingleFalses + numSingleTrues > 0 ? 1 : 0;
assertThat(terms.getBuckets().size(), equalTo(bucketCount)); assertThat(terms.getBuckets().size(), equalTo(bucketCount));
Terms.Bucket bucket = terms.getBucketByKey("0"); Terms.Bucket bucket = terms.getBucketByKey("false");
if (numSingleFalses == 0) { if (numSingleFalses == 0) {
assertNull(bucket); assertNull(bucket);
} else { } else {
assertNotNull(bucket); assertNotNull(bucket);
assertEquals(numSingleFalses, bucket.getDocCount()); assertEquals(numSingleFalses, bucket.getDocCount());
assertEquals("false", bucket.getKeyAsString());
} }
bucket = terms.getBucketByKey("1"); bucket = terms.getBucketByKey("true");
if (numSingleTrues == 0) { if (numSingleTrues == 0) {
assertNull(bucket); assertNull(bucket);
} else { } else {
assertNotNull(bucket); assertNotNull(bucket);
assertEquals(numSingleTrues, bucket.getDocCount()); assertEquals(numSingleTrues, bucket.getDocCount());
assertEquals("true", bucket.getKeyAsString());
} }
} }
@ -131,20 +133,22 @@ public class BooleanTermsIT extends ESIntegTestCase {
final int bucketCount = numMultiFalses > 0 && numMultiTrues > 0 ? 2 : numMultiFalses + numMultiTrues > 0 ? 1 : 0; final int bucketCount = numMultiFalses > 0 && numMultiTrues > 0 ? 2 : numMultiFalses + numMultiTrues > 0 ? 1 : 0;
assertThat(terms.getBuckets().size(), equalTo(bucketCount)); assertThat(terms.getBuckets().size(), equalTo(bucketCount));
Terms.Bucket bucket = terms.getBucketByKey("0"); Terms.Bucket bucket = terms.getBucketByKey("false");
if (numMultiFalses == 0) { if (numMultiFalses == 0) {
assertNull(bucket); assertNull(bucket);
} else { } else {
assertNotNull(bucket); assertNotNull(bucket);
assertEquals(numMultiFalses, bucket.getDocCount()); assertEquals(numMultiFalses, bucket.getDocCount());
assertEquals("false", bucket.getKeyAsString());
} }
bucket = terms.getBucketByKey("1"); bucket = terms.getBucketByKey("true");
if (numMultiTrues == 0) { if (numMultiTrues == 0) {
assertNull(bucket); assertNull(bucket);
} else { } else {
assertNotNull(bucket); assertNotNull(bucket);
assertEquals(numMultiTrues, bucket.getDocCount()); assertEquals(numMultiTrues, bucket.getDocCount());
assertEquals("true", bucket.getKeyAsString());
} }
} }

View File

@ -423,10 +423,10 @@ public class NestedIT extends ESIntegTestCase {
Terms startDate = response.getAggregations().get("startDate"); Terms startDate = response.getAggregations().get("startDate");
assertThat(startDate.getBuckets().size(), equalTo(2)); assertThat(startDate.getBuckets().size(), equalTo(2));
Terms.Bucket bucket = startDate.getBucketByKey("1414800000000"); // 2014-11-01T00:00:00.000Z Terms.Bucket bucket = startDate.getBucketByKey("2014-11-01T00:00:00.000Z");
assertThat(bucket.getDocCount(), equalTo(1l)); assertThat(bucket.getDocCount(), equalTo(1l));
Terms endDate = bucket.getAggregations().get("endDate"); Terms endDate = bucket.getAggregations().get("endDate");
bucket = endDate.getBucketByKey("1417305600000"); // 2014-11-30T00:00:00.000Z bucket = endDate.getBucketByKey("2014-11-30T00:00:00.000Z");
assertThat(bucket.getDocCount(), equalTo(1l)); assertThat(bucket.getDocCount(), equalTo(1l));
Terms period = bucket.getAggregations().get("period"); Terms period = bucket.getAggregations().get("period");
bucket = period.getBucketByKey("2014-11"); bucket = period.getBucketByKey("2014-11");
@ -440,10 +440,10 @@ public class NestedIT extends ESIntegTestCase {
Terms tags = nestedTags.getAggregations().get("tag"); Terms tags = nestedTags.getAggregations().get("tag");
assertThat(tags.getBuckets().size(), equalTo(0)); // and this must be empty assertThat(tags.getBuckets().size(), equalTo(0)); // and this must be empty
bucket = startDate.getBucketByKey("1417392000000"); // 2014-12-01T00:00:00.000Z bucket = startDate.getBucketByKey("2014-12-01T00:00:00.000Z");
assertThat(bucket.getDocCount(), equalTo(1l)); assertThat(bucket.getDocCount(), equalTo(1l));
endDate = bucket.getAggregations().get("endDate"); endDate = bucket.getAggregations().get("endDate");
bucket = endDate.getBucketByKey("1419984000000"); // 2014-12-31T00:00:00.000Z bucket = endDate.getBucketByKey("2014-12-31T00:00:00.000Z");
assertThat(bucket.getDocCount(), equalTo(1l)); assertThat(bucket.getDocCount(), equalTo(1l));
period = bucket.getAggregations().get("period"); period = bucket.getAggregations().get("period");
bucket = period.getBucketByKey("2014-12"); bucket = period.getBucketByKey("2014-12");