Use different field names based on the data type in aggregations tests.

Tests fail once in a while because of a ClassCastException at the mvel level.
We suspect that this happens because a script that is JIT-ed on a specific
data type cannot later be used with another one, but we didn't manage to
reproduce in our development environments, so let's try to change the field
names to see if this error keeps occurring.
This commit is contained in:
Adrien Grand 2014-01-24 13:44:46 +01:00
parent 663e25ae63
commit 9d10c2fca8
5 changed files with 198 additions and 187 deletions

View File

@ -52,6 +52,8 @@ import static org.hamcrest.core.IsNull.notNullValue;
public class DoubleTermsTests extends ElasticsearchIntegrationTest { public class DoubleTermsTests extends ElasticsearchIntegrationTest {
private static final int NUM_DOCS = 5; // TODO: randomize the size? private static final int NUM_DOCS = 5; // TODO: randomize the size?
private static final String SINGLE_VALUED_FIELD_NAME = "d_value";
private static final String MULTI_VALUED_FIELD_NAME = "d_values";
@Override @Override
public Settings indexSettings() { public Settings indexSettings() {
@ -69,8 +71,8 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
for (int i = 0; i < lowcardBuilders.length; i++) { for (int i = 0; i < lowcardBuilders.length; i++) {
lowcardBuilders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder() lowcardBuilders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder()
.startObject() .startObject()
.field("value", (double) i) .field(SINGLE_VALUED_FIELD_NAME, (double) i)
.startArray("values").value((double)i).value(i + 1d).endArray() .startArray(MULTI_VALUED_FIELD_NAME).value((double)i).value(i + 1d).endArray()
.endObject()); .endObject());
} }
@ -79,8 +81,8 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
for (int i = 0; i < highCardBuilders.length; i++) { for (int i = 0; i < highCardBuilders.length; i++) {
highCardBuilders[i] = client().prepareIndex("idx", "high_card_type").setSource(jsonBuilder() highCardBuilders[i] = client().prepareIndex("idx", "high_card_type").setSource(jsonBuilder()
.startObject() .startObject()
.field("value", (double) i) .field(SINGLE_VALUED_FIELD_NAME, (double) i)
.startArray("values").value((double)i).value(i + 1d).endArray() .startArray(MULTI_VALUED_FIELD_NAME).value((double)i).value(i + 1d).endArray()
.endObject()); .endObject());
} }
indexRandom(true, highCardBuilders); indexRandom(true, highCardBuilders);
@ -94,7 +96,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void sizeIsZero() { public void sizeIsZero() {
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type") SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.minDocCount(randomInt(1)) .minDocCount(randomInt(1))
.size(0)) .size(0))
.execute().actionGet(); .execute().actionGet();
@ -111,7 +113,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void singleValueField() throws Exception { public void singleValueField() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value")) .field(SINGLE_VALUED_FIELD_NAME))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -135,7 +137,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void singleValueField_WithMaxSize() throws Exception { public void singleValueField_WithMaxSize() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type") SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.size(20) .size(20)
.order(Terms.Order.term(true))) // we need to sort by terms cause we're checking the first 20 values .order(Terms.Order.term(true))) // we need to sort by terms cause we're checking the first 20 values
.execute().actionGet(); .execute().actionGet();
@ -161,7 +163,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void singleValueField_OrderedByTermAsc() throws Exception { public void singleValueField_OrderedByTermAsc() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.term(true))) .order(Terms.Order.term(true)))
.execute().actionGet(); .execute().actionGet();
@ -187,7 +189,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void singleValueField_OrderedByTermDesc() throws Exception { public void singleValueField_OrderedByTermDesc() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.term(false))) .order(Terms.Order.term(false)))
.execute().actionGet(); .execute().actionGet();
@ -213,8 +215,8 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void singleValuedField_WithSubAggregation() throws Exception { public void singleValuedField_WithSubAggregation() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.subAggregation(sum("sum").field("values"))) .subAggregation(sum("sum").field(MULTI_VALUED_FIELD_NAME)))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -241,7 +243,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void singleValuedField_WithSubAggregation_Inherited() throws Exception { public void singleValuedField_WithSubAggregation_Inherited() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -269,7 +271,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void singleValuedField_WithValueScript() throws Exception { public void singleValuedField_WithValueScript() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.script("_value + 1")) .script("_value + 1"))
.execute().actionGet(); .execute().actionGet();
@ -294,7 +296,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void multiValuedField() throws Exception { public void multiValuedField() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("values")) .field(MULTI_VALUED_FIELD_NAME))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -322,7 +324,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void multiValuedField_WithValueScript() throws Exception { public void multiValuedField_WithValueScript() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.script("_value + 1")) .script("_value + 1"))
.execute().actionGet(); .execute().actionGet();
@ -351,7 +353,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void multiValuedField_WithValueScript_NotUnique() throws Exception { public void multiValuedField_WithValueScript_NotUnique() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.script("(long) _value / 1000 + 1")) .script("(long) _value / 1000 + 1"))
.execute().actionGet(); .execute().actionGet();
@ -391,7 +393,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws Exception { public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.script("_value + 1") .script("_value + 1")
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -428,7 +430,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void script_SingleValue() throws Exception { public void script_SingleValue() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.script("doc['value'].value")) .script("doc['" + MULTI_VALUED_FIELD_NAME + "'].value"))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -452,7 +454,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void script_SingleValue_WithSubAggregator_Inherited() throws Exception { public void script_SingleValue_WithSubAggregator_Inherited() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -480,7 +482,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void script_MultiValued() throws Exception { public void script_MultiValued() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.script("doc['values'].values")) .script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values"))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -514,7 +516,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.script("doc['values'].values") .script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -531,7 +533,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void script_MultiValued_WithAggregatorInherited_WithExplicitType() throws Exception { public void script_MultiValued_WithAggregatorInherited_WithExplicitType() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.script("doc['values'].values") .script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
.valueType(Terms.ValueType.DOUBLE) .valueType(Terms.ValueType.DOUBLE)
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -568,7 +570,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void unmapped() throws Exception { public void unmapped() throws Exception {
SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type") SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.size(randomInt(5))) .size(randomInt(5)))
.execute().actionGet(); .execute().actionGet();
@ -585,7 +587,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
public void partiallyUnmapped() throws Exception { public void partiallyUnmapped() throws Exception {
SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type") SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value")) .field(SINGLE_VALUED_FIELD_NAME))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -607,19 +609,19 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
@Test @Test
public void emptyAggregation() throws Exception { public void emptyAggregation() throws Exception {
prepareCreate("empty_bucket_idx").addMapping("type", "value", "type=integer").execute().actionGet(); prepareCreate("empty_bucket_idx").addMapping("type", SINGLE_VALUED_FIELD_NAME, "type=integer").execute().actionGet();
List<IndexRequestBuilder> builders = new ArrayList<IndexRequestBuilder>(); List<IndexRequestBuilder> builders = new ArrayList<IndexRequestBuilder>();
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
builders.add(client().prepareIndex("empty_bucket_idx", "type", ""+i).setSource(jsonBuilder() builders.add(client().prepareIndex("empty_bucket_idx", "type", ""+i).setSource(jsonBuilder()
.startObject() .startObject()
.field("value", i*2) .field(SINGLE_VALUED_FIELD_NAME, i*2)
.endObject())); .endObject()));
} }
indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()])); indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()]));
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx") SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
.setQuery(matchAllQuery()) .setQuery(matchAllQuery())
.addAggregation(histogram("histo").field("value").interval(1l).minDocCount(0) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(1l).minDocCount(0)
.subAggregation(terms("terms"))) .subAggregation(terms("terms")))
.execute().actionGet(); .execute().actionGet();
@ -640,9 +642,9 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
boolean asc = true; boolean asc = true;
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("avg_i", asc)) .order(Terms.Order.aggregation("avg_i", asc))
.subAggregation(avg("avg_i").field("value")) .subAggregation(avg("avg_i").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
@ -671,7 +673,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
client().prepareSearch("idx").setTypes("type") client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("avg_i", true)) .order(Terms.Order.aggregation("avg_i", true))
).execute().actionGet(); ).execute().actionGet();
@ -689,7 +691,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
client().prepareSearch("idx").setTypes("type") client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("filter", true)) .order(Terms.Order.aggregation("filter", true))
.subAggregation(filter("filter").filter(FilterBuilders.termFilter("foo", "bar"))) .subAggregation(filter("filter").filter(FilterBuilders.termFilter("foo", "bar")))
).execute().actionGet(); ).execute().actionGet();
@ -708,9 +710,9 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
client().prepareSearch("idx").setTypes("type") client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats.foo", true)) .order(Terms.Order.aggregation("stats.foo", true))
.subAggregation(stats("stats").field("value")) .subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
fail("Expected search to fail when trying to sort terms aggregation by multi-valued sug-aggregation " + fail("Expected search to fail when trying to sort terms aggregation by multi-valued sug-aggregation " +
@ -728,9 +730,9 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
client().prepareSearch("idx").setTypes("type") client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats", true)) .order(Terms.Order.aggregation("stats", true))
.subAggregation(stats("stats").field("value")) .subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
fail("Expected search to fail when trying to sort terms aggregation by multi-valued sug-aggregation " + fail("Expected search to fail when trying to sort terms aggregation by multi-valued sug-aggregation " +
@ -746,9 +748,9 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
boolean asc = false; boolean asc = false;
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("avg_i", asc)) .order(Terms.Order.aggregation("avg_i", asc))
.subAggregation(avg("avg_i").field("value")) .subAggregation(avg("avg_i").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
@ -778,9 +780,9 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
boolean asc = true; boolean asc = true;
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats.avg", asc)) .order(Terms.Order.aggregation("stats.avg", asc))
.subAggregation(stats("stats").field("value")) .subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -808,9 +810,9 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
boolean asc = false; boolean asc = false;
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats.avg", asc)) .order(Terms.Order.aggregation("stats.avg", asc))
.subAggregation(stats("stats").field("value")) .subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -838,9 +840,9 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
boolean asc = true; boolean asc = true;
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats.variance", asc)) .order(Terms.Order.aggregation("stats.variance", asc))
.subAggregation(extendedStats("stats").field("value")) .subAggregation(extendedStats("stats").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);

View File

@ -48,6 +48,9 @@ import static org.hamcrest.core.IsNull.notNullValue;
*/ */
public class HistogramTests extends ElasticsearchIntegrationTest { public class HistogramTests extends ElasticsearchIntegrationTest {
private static final String SINGLE_VALUED_FIELD_NAME = "l_value";
private static final String MULTI_VALUED_FIELD_NAME = "l_values";
@Override @Override
public Settings indexSettings() { public Settings indexSettings() {
return ImmutableSettings.builder() return ImmutableSettings.builder()
@ -92,8 +95,8 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
for (int i = 0; i < builders.length; i++) { for (int i = 0; i < builders.length; i++) {
builders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder() builders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder()
.startObject() .startObject()
.field("value", i + 1) .field(SINGLE_VALUED_FIELD_NAME, i + 1)
.startArray("values").value(i + 1).value(i + 2).endArray() .startArray(MULTI_VALUED_FIELD_NAME).value(i + 1).value(i + 2).endArray()
.field("tag", "tag" + i) .field("tag", "tag" + i)
.endObject()); .endObject());
} }
@ -104,7 +107,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void singleValuedField() throws Exception { public void singleValuedField() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("value").interval(interval)) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -126,7 +129,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void singleValuedField_OrderedByKeyAsc() throws Exception { public void singleValuedField_OrderedByKeyAsc() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("value").interval(interval).order(Histogram.Order.KEY_ASC)) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.KEY_ASC))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -148,7 +151,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void singleValuedField_OrderedByKeyDesc() throws Exception { public void singleValuedField_OrderedByKeyDesc() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("value").interval(interval).order(Histogram.Order.KEY_DESC)) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.KEY_DESC))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -170,7 +173,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void singleValuedField_OrderedByCountAsc() throws Exception { public void singleValuedField_OrderedByCountAsc() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("value").interval(interval).order(Histogram.Order.COUNT_ASC)) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.COUNT_ASC))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -198,7 +201,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void singleValuedField_OrderedByCountDesc() throws Exception { public void singleValuedField_OrderedByCountDesc() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("value").interval(interval).order(Histogram.Order.COUNT_DESC)) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.COUNT_DESC))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -226,8 +229,8 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void singleValuedField_WithSubAggregation() throws Exception { public void singleValuedField_WithSubAggregation() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("value").interval(interval) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval)
.subAggregation(sum("sum").field("value"))) .subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -259,7 +262,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void singleValuedField_WithSubAggregation_Inherited() throws Exception { public void singleValuedField_WithSubAggregation_Inherited() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("value").interval(interval) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval)
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -292,8 +295,8 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void singleValuedField_OrderedBySubAggregationAsc() throws Exception { public void singleValuedField_OrderedBySubAggregationAsc() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("value").interval(interval).order(Histogram.Order.aggregation("sum", true)) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.aggregation("sum", true))
.subAggregation(sum("sum").field("value"))) .subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -331,8 +334,8 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void singleValuedField_OrderedBySubAggregationDesc() throws Exception { public void singleValuedField_OrderedBySubAggregationDesc() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("value").interval(interval).order(Histogram.Order.aggregation("sum", false)) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.aggregation("sum", false))
.subAggregation(sum("sum").field("value"))) .subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -370,7 +373,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void singleValuedField_OrderedByMultiValuedSubAggregationAsc_Inherited() throws Exception { public void singleValuedField_OrderedByMultiValuedSubAggregationAsc_Inherited() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("value").interval(interval).order(Histogram.Order.aggregation("stats.sum", true)) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.aggregation("stats.sum", true))
.subAggregation(stats("stats"))) .subAggregation(stats("stats")))
.execute().actionGet(); .execute().actionGet();
@ -409,8 +412,8 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void singleValuedField_OrderedByMultiValuedSubAggregationDesc() throws Exception { public void singleValuedField_OrderedByMultiValuedSubAggregationDesc() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("value").interval(interval).order(Histogram.Order.aggregation("stats.sum", false)) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.aggregation("stats.sum", false))
.subAggregation(stats("stats").field("value"))) .subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME)))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -448,7 +451,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void singleValuedField_WithValueScript() throws Exception { public void singleValuedField_WithValueScript() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("value").script("_value + 1").interval(interval)) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).script("_value + 1").interval(interval))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -476,7 +479,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void multiValuedField() throws Exception { public void multiValuedField() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("values").interval(interval)) .addAggregation(histogram("histo").field(MULTI_VALUED_FIELD_NAME).interval(interval))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -498,7 +501,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void multiValuedField_OrderedByKeyDesc() throws Exception { public void multiValuedField_OrderedByKeyDesc() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("values").interval(interval).order(Histogram.Order.KEY_DESC)) .addAggregation(histogram("histo").field(MULTI_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.KEY_DESC))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -520,7 +523,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void multiValuedField_WithValueScript() throws Exception { public void multiValuedField_WithValueScript() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("values").script("_value + 1").interval(interval)) .addAggregation(histogram("histo").field(MULTI_VALUED_FIELD_NAME).script("_value + 1").interval(interval))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -553,8 +556,8 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws Exception { public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").field("values").script("_value + 1").interval(interval) .addAggregation(histogram("histo").field(MULTI_VALUED_FIELD_NAME).script("_value + 1").interval(interval)
.subAggregation(terms("values").order(Terms.Order.term(true)))) .subAggregation(terms(MULTI_VALUED_FIELD_NAME).order(Terms.Order.term(true))))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -581,9 +584,9 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
assertThat(bucket, notNullValue()); assertThat(bucket, notNullValue());
assertThat(bucket.getKey(), equalTo((long) i * interval)); assertThat(bucket.getKey(), equalTo((long) i * interval));
assertThat(bucket.getDocCount(), equalTo(counts[i])); assertThat(bucket.getDocCount(), equalTo(counts[i]));
Terms terms = bucket.getAggregations().get("values"); Terms terms = bucket.getAggregations().get(MULTI_VALUED_FIELD_NAME);
assertThat(terms, notNullValue()); assertThat(terms, notNullValue());
assertThat(terms.getName(), equalTo("values")); assertThat(terms.getName(), equalTo(MULTI_VALUED_FIELD_NAME));
int minTerm = Math.max(2, i * interval - 1); int minTerm = Math.max(2, i * interval - 1);
int maxTerm = Math.min(numDocs + 2, (i + 1) * interval); int maxTerm = Math.min(numDocs + 2, (i + 1) * interval);
assertThat(terms.buckets().size(), equalTo(maxTerm - minTerm + 1)); assertThat(terms.buckets().size(), equalTo(maxTerm - minTerm + 1));
@ -597,7 +600,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void script_SingleValue() throws Exception { public void script_SingleValue() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").script("doc['value'].value").interval(interval)) .addAggregation(histogram("histo").script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value").interval(interval))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -619,7 +622,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void script_SingleValue_WithSubAggregator_Inherited() throws Exception { public void script_SingleValue_WithSubAggregator_Inherited() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").script("doc['value'].value").interval(interval) .addAggregation(histogram("histo").script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value").interval(interval)
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -652,7 +655,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void script_MultiValued() throws Exception { public void script_MultiValued() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").script("doc['values'].values").interval(interval)) .addAggregation(histogram("histo").script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values").interval(interval))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -674,7 +677,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void script_MultiValued_WithAggregatorInherited() throws Exception { public void script_MultiValued_WithAggregatorInherited() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(histogram("histo").script("doc['values'].values").interval(interval) .addAggregation(histogram("histo").script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values").interval(interval)
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -708,7 +711,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void unmapped() throws Exception { public void unmapped() throws Exception {
SearchResponse response = client().prepareSearch("idx_unmapped") SearchResponse response = client().prepareSearch("idx_unmapped")
.addAggregation(histogram("histo").field("value").interval(interval)) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -723,7 +726,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void partiallyUnmapped() throws Exception { public void partiallyUnmapped() throws Exception {
SearchResponse response = client().prepareSearch("idx", "idx_unmapped") SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
.addAggregation(histogram("histo").field("value").interval(interval)) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -744,19 +747,19 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
@Test @Test
public void emptyAggregation() throws Exception { public void emptyAggregation() throws Exception {
prepareCreate("empty_bucket_idx").addMapping("type", "value", "type=integer").execute().actionGet(); prepareCreate("empty_bucket_idx").addMapping("type", SINGLE_VALUED_FIELD_NAME, "type=integer").execute().actionGet();
List<IndexRequestBuilder> builders = new ArrayList<IndexRequestBuilder>(); List<IndexRequestBuilder> builders = new ArrayList<IndexRequestBuilder>();
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
builders.add(client().prepareIndex("empty_bucket_idx", "type", "" + i).setSource(jsonBuilder() builders.add(client().prepareIndex("empty_bucket_idx", "type", "" + i).setSource(jsonBuilder()
.startObject() .startObject()
.field("value", i * 2) .field(SINGLE_VALUED_FIELD_NAME, i * 2)
.endObject())); .endObject()));
} }
indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()])); indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()]));
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx") SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
.setQuery(matchAllQuery()) .setQuery(matchAllQuery())
.addAggregation(histogram("histo").field("value").interval(1l).minDocCount(0) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(1l).minDocCount(0)
.subAggregation(histogram("sub_histo").interval(1l))) .subAggregation(histogram("sub_histo").interval(1l)))
.execute().actionGet(); .execute().actionGet();

View File

@ -52,6 +52,8 @@ import static org.hamcrest.core.IsNull.notNullValue;
public class LongTermsTests extends ElasticsearchIntegrationTest { public class LongTermsTests extends ElasticsearchIntegrationTest {
private static final int NUM_DOCS = 5; // TODO randomize the size? private static final int NUM_DOCS = 5; // TODO randomize the size?
private static final String SINGLE_VALUED_FIELD_NAME = "l_value";
private static final String MULTI_VALUED_FIELD_NAME = "l_values";
@Override @Override
public Settings indexSettings() { public Settings indexSettings() {
@ -68,8 +70,8 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
for (int i = 0; i < lowCardBuilders.length; i++) { for (int i = 0; i < lowCardBuilders.length; i++) {
lowCardBuilders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder() lowCardBuilders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder()
.startObject() .startObject()
.field("value", i) .field(SINGLE_VALUED_FIELD_NAME, i)
.startArray("values").value(i).value(i + 1).endArray() .startArray(MULTI_VALUED_FIELD_NAME).value(i).value(i + 1).endArray()
.endObject()); .endObject());
} }
indexRandom(randomBoolean(), lowCardBuilders); indexRandom(randomBoolean(), lowCardBuilders);
@ -77,8 +79,8 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
for (int i = 0; i < highCardBuilders.length; i++) { for (int i = 0; i < highCardBuilders.length; i++) {
highCardBuilders[i] = client().prepareIndex("idx", "high_card_type").setSource(jsonBuilder() highCardBuilders[i] = client().prepareIndex("idx", "high_card_type").setSource(jsonBuilder()
.startObject() .startObject()
.field("value", i) .field(SINGLE_VALUED_FIELD_NAME, i)
.startArray("values").value(i).value(i + 1).endArray() .startArray(MULTI_VALUED_FIELD_NAME).value(i).value(i + 1).endArray()
.endObject()); .endObject());
} }
@ -92,7 +94,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void sizeIsZero() { public void sizeIsZero() {
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type") SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.minDocCount(randomInt(1)) .minDocCount(randomInt(1))
.size(0)) .size(0))
.execute().actionGet(); .execute().actionGet();
@ -109,7 +111,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void singleValueField() throws Exception { public void singleValueField() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value")) .field(SINGLE_VALUED_FIELD_NAME))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -133,7 +135,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void singleValueField_WithMaxSize() throws Exception { public void singleValueField_WithMaxSize() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type") SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.size(20) .size(20)
.order(Terms.Order.term(true))) // we need to sort by terms cause we're checking the first 20 values .order(Terms.Order.term(true))) // we need to sort by terms cause we're checking the first 20 values
.execute().actionGet(); .execute().actionGet();
@ -159,7 +161,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void singleValueField_OrderedByTermAsc() throws Exception { public void singleValueField_OrderedByTermAsc() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.term(true))) .order(Terms.Order.term(true)))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -183,7 +185,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void singleValueField_OrderedByTermDesc() throws Exception { public void singleValueField_OrderedByTermDesc() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.term(false))) .order(Terms.Order.term(false)))
.execute().actionGet(); .execute().actionGet();
@ -209,8 +211,8 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void singleValuedField_WithSubAggregation() throws Exception { public void singleValuedField_WithSubAggregation() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.subAggregation(sum("sum").field("values"))) .subAggregation(sum("sum").field(MULTI_VALUED_FIELD_NAME)))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -237,7 +239,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void singleValuedField_WithSubAggregation_Inherited() throws Exception { public void singleValuedField_WithSubAggregation_Inherited() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -265,7 +267,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void singleValuedField_WithValueScript() throws Exception { public void singleValuedField_WithValueScript() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.script("_value + 1")) .script("_value + 1"))
.execute().actionGet(); .execute().actionGet();
@ -290,7 +292,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void multiValuedField() throws Exception { public void multiValuedField() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("values")) .field(MULTI_VALUED_FIELD_NAME))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -318,7 +320,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void multiValuedField_WithValueScript() throws Exception { public void multiValuedField_WithValueScript() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.script("_value - 1")) .script("_value - 1"))
.execute().actionGet(); .execute().actionGet();
@ -347,7 +349,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void multiValuedField_WithValueScript_NotUnique() throws Exception { public void multiValuedField_WithValueScript_NotUnique() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.script("floor(_value / 1000 + 1)")) .script("floor(_value / 1000 + 1)"))
.execute().actionGet(); .execute().actionGet();
@ -387,7 +389,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws Exception { public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.script("_value + 1") .script("_value + 1")
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -424,7 +426,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void script_SingleValue() throws Exception { public void script_SingleValue() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.script("doc['value'].value")) .script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value"))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -448,7 +450,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void script_SingleValue_WithSubAggregator_Inherited() throws Exception { public void script_SingleValue_WithSubAggregator_Inherited() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -476,7 +478,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void script_MultiValued() throws Exception { public void script_MultiValued() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.script("doc['values'].values")) .script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values"))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -510,7 +512,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.script("doc['values'].values") .script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -525,7 +527,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void script_MultiValued_WithAggregatorInherited_WithExplicitType() throws Exception { public void script_MultiValued_WithAggregatorInherited_WithExplicitType() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.script("doc['values'].values") .script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
.valueType(Terms.ValueType.LONG) .valueType(Terms.ValueType.LONG)
.subAggregation(sum("sum"))) .subAggregation(sum("sum")))
.execute().actionGet(); .execute().actionGet();
@ -562,7 +564,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void unmapped() throws Exception { public void unmapped() throws Exception {
SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type") SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.size(randomInt(5))) .size(randomInt(5)))
.execute().actionGet(); .execute().actionGet();
@ -579,7 +581,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
public void partiallyUnmapped() throws Exception { public void partiallyUnmapped() throws Exception {
SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type") SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value")) .field(SINGLE_VALUED_FIELD_NAME))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -601,19 +603,19 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
@Test @Test
public void emptyAggregation() throws Exception { public void emptyAggregation() throws Exception {
prepareCreate("empty_bucket_idx").addMapping("type", "value", "type=integer").execute().actionGet(); prepareCreate("empty_bucket_idx").addMapping("type", SINGLE_VALUED_FIELD_NAME, "type=integer").execute().actionGet();
List<IndexRequestBuilder> builders = new ArrayList<IndexRequestBuilder>(); List<IndexRequestBuilder> builders = new ArrayList<IndexRequestBuilder>();
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
builders.add(client().prepareIndex("empty_bucket_idx", "type", ""+i).setSource(jsonBuilder() builders.add(client().prepareIndex("empty_bucket_idx", "type", ""+i).setSource(jsonBuilder()
.startObject() .startObject()
.field("value", i*2) .field(SINGLE_VALUED_FIELD_NAME, i*2)
.endObject())); .endObject()));
} }
indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()])); indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()]));
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx") SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
.setQuery(matchAllQuery()) .setQuery(matchAllQuery())
.addAggregation(histogram("histo").field("value").interval(1l).minDocCount(0) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(1l).minDocCount(0)
.subAggregation(terms("terms"))) .subAggregation(terms("terms")))
.execute().actionGet(); .execute().actionGet();
@ -634,9 +636,9 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
boolean asc = true; boolean asc = true;
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("avg_i", asc)) .order(Terms.Order.aggregation("avg_i", asc))
.subAggregation(avg("avg_i").field("value")) .subAggregation(avg("avg_i").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
@ -665,7 +667,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
client().prepareSearch("idx").setTypes("type") client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("avg_i", true)) .order(Terms.Order.aggregation("avg_i", true))
).execute().actionGet(); ).execute().actionGet();
@ -683,7 +685,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
client().prepareSearch("idx").setTypes("type") client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("filter", true)) .order(Terms.Order.aggregation("filter", true))
.subAggregation(filter("filter").filter(FilterBuilders.termFilter("foo", "bar"))) .subAggregation(filter("filter").filter(FilterBuilders.termFilter("foo", "bar")))
).execute().actionGet(); ).execute().actionGet();
@ -702,9 +704,9 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
client().prepareSearch("idx").setTypes("type") client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats.foo", true)) .order(Terms.Order.aggregation("stats.foo", true))
.subAggregation(stats("stats").field("value")) .subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
fail("Expected search to fail when trying to sort terms aggregation by multi-valued sug-aggregation " + fail("Expected search to fail when trying to sort terms aggregation by multi-valued sug-aggregation " +
@ -722,9 +724,9 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
client().prepareSearch("idx").setTypes("type") client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats", true)) .order(Terms.Order.aggregation("stats", true))
.subAggregation(stats("stats").field("value")) .subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
fail("Expected search to fail when trying to sort terms aggregation by multi-valued sug-aggregation " + fail("Expected search to fail when trying to sort terms aggregation by multi-valued sug-aggregation " +
@ -740,9 +742,9 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
boolean asc = false; boolean asc = false;
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("avg_i", asc)) .order(Terms.Order.aggregation("avg_i", asc))
.subAggregation(avg("avg_i").field("value")) .subAggregation(avg("avg_i").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
@ -772,9 +774,9 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
boolean asc = true; boolean asc = true;
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats.avg", asc)) .order(Terms.Order.aggregation("stats.avg", asc))
.subAggregation(stats("stats").field("value")) .subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -802,9 +804,9 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
boolean asc = false; boolean asc = false;
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats.avg", asc)) .order(Terms.Order.aggregation("stats.avg", asc))
.subAggregation(stats("stats").field("value")) .subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -832,9 +834,9 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
boolean asc = true; boolean asc = true;
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats.variance", asc)) .order(Terms.Order.aggregation("stats.variance", asc))
.subAggregation(extendedStats("stats").field("value")) .subAggregation(extendedStats("stats").field(SINGLE_VALUED_FIELD_NAME))
).execute().actionGet(); ).execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);

View File

@ -48,6 +48,8 @@ import static org.hamcrest.core.IsNull.notNullValue;
*/ */
public class RangeTests extends ElasticsearchIntegrationTest { public class RangeTests extends ElasticsearchIntegrationTest {
private static final String SINGLE_VALUED_FIELD_NAME = "l_value";
private static final String MULTI_VALUED_FIELD_NAME = "l_values";
@Override @Override
public Settings indexSettings() { public Settings indexSettings() {
@ -67,8 +69,8 @@ public class RangeTests extends ElasticsearchIntegrationTest {
for (int i = 0; i < builders.length; i++) { for (int i = 0; i < builders.length; i++) {
builders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder() builders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder()
.startObject() .startObject()
.field("value", i+1) .field(SINGLE_VALUED_FIELD_NAME, i+1)
.startArray("values").value(i+1).value(i+2).endArray() .startArray(MULTI_VALUED_FIELD_NAME).value(i+1).value(i+2).endArray()
.endObject()); .endObject());
} }
indexRandom(true, builders); indexRandom(true, builders);
@ -79,8 +81,8 @@ public class RangeTests extends ElasticsearchIntegrationTest {
@Test @Test
public void rangeAsSubAggregation() throws Exception { public void rangeAsSubAggregation() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(terms("terms").field("values").size(100).subAggregation( .addAggregation(terms("terms").field(MULTI_VALUED_FIELD_NAME).size(100).subAggregation(
range("range").field("value") range("range").field(SINGLE_VALUED_FIELD_NAME)
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
.addUnboundedFrom(6))) .addUnboundedFrom(6)))
@ -130,7 +132,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void singleValueField() throws Exception { public void singleValueField() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
.addUnboundedFrom(6)) .addUnboundedFrom(6))
@ -170,7 +172,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void singleValueField_WithCustomKey() throws Exception { public void singleValueField_WithCustomKey() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.addUnboundedTo("r1", 3) .addUnboundedTo("r1", 3)
.addRange("r2", 3, 6) .addRange("r2", 3, 6)
.addUnboundedFrom("r3", 6)) .addUnboundedFrom("r3", 6))
@ -210,11 +212,11 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void singleValuedField_WithSubAggregation() throws Exception { public void singleValuedField_WithSubAggregation() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
.addUnboundedFrom(6) .addUnboundedFrom(6)
.subAggregation(sum("sum").field("value"))) .subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -264,7 +266,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void singleValuedField_WithSubAggregation_Inherited() throws Exception { public void singleValuedField_WithSubAggregation_Inherited() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
.addUnboundedFrom(6) .addUnboundedFrom(6)
@ -318,7 +320,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void singleValuedField_WithValueScript() throws Exception { public void singleValuedField_WithValueScript() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.script("_value + 1") .script("_value + 1")
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
@ -372,7 +374,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void multiValuedField() throws Exception { public void multiValuedField() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
.addUnboundedFrom(6)) .addUnboundedFrom(6))
@ -425,7 +427,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void multiValuedField_WithValueScript() throws Exception { public void multiValuedField_WithValueScript() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.script("_value + 1") .script("_value + 1")
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
@ -483,7 +485,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws Exception { public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.script("_value + 1") .script("_value + 1")
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
@ -541,7 +543,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void script_SingleValue() throws Exception { public void script_SingleValue() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.script("doc['value'].value") .script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value")
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
.addUnboundedFrom(6)) .addUnboundedFrom(6))
@ -581,7 +583,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void script_SingleValue_WithSubAggregator_Inherited() throws Exception { public void script_SingleValue_WithSubAggregator_Inherited() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.script("doc['value'].value") .script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value")
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
.addUnboundedFrom(6) .addUnboundedFrom(6)
@ -635,7 +637,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void emptyRange() throws Exception { public void emptyRange() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.addUnboundedTo(-1) .addUnboundedTo(-1)
.addUnboundedFrom(1000)) .addUnboundedFrom(1000))
.execute().actionGet(); .execute().actionGet();
@ -667,7 +669,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void script_MultiValued() throws Exception { public void script_MultiValued() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.script("doc['values'].values") .script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
.addUnboundedFrom(6)) .addUnboundedFrom(6))
@ -724,7 +726,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void script_MultiValued_WithAggregatorInherited() throws Exception { public void script_MultiValued_WithAggregatorInherited() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.script("doc['values'].values") .script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
.addUnboundedTo("r1", 3) .addUnboundedTo("r1", 3)
.addRange("r2", 3, 6) .addRange("r2", 3, 6)
.addUnboundedFrom("r3", 6) .addUnboundedFrom("r3", 6)
@ -781,7 +783,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void unmapped() throws Exception { public void unmapped() throws Exception {
SearchResponse response = client().prepareSearch("idx_unmapped") SearchResponse response = client().prepareSearch("idx_unmapped")
.addAggregation(range("range") .addAggregation(range("range")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
.addUnboundedFrom(6)) .addUnboundedFrom(6))
@ -823,7 +825,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx", "idx_unmapped") SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
.addAggregation(range("range") .addAggregation(range("range")
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.addUnboundedTo(3) .addUnboundedTo(3)
.addRange(3, 6) .addRange(3, 6)
.addUnboundedFrom(6)) .addUnboundedFrom(6))
@ -863,7 +865,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
public void overlappingRanges() throws Exception { public void overlappingRanges() throws Exception {
SearchResponse response = client().prepareSearch("idx") SearchResponse response = client().prepareSearch("idx")
.addAggregation(range("range") .addAggregation(range("range")
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.addUnboundedTo(5) .addUnboundedTo(5)
.addRange(3, 6) .addRange(3, 6)
.addRange(4, 5) .addRange(4, 5)
@ -909,19 +911,19 @@ public class RangeTests extends ElasticsearchIntegrationTest {
@Test @Test
public void emptyAggregation() throws Exception { public void emptyAggregation() throws Exception {
prepareCreate("empty_bucket_idx").addMapping("type", "value", "type=integer").execute().actionGet(); prepareCreate("empty_bucket_idx").addMapping("type", SINGLE_VALUED_FIELD_NAME, "type=integer").execute().actionGet();
List<IndexRequestBuilder> builders = new ArrayList<IndexRequestBuilder>(); List<IndexRequestBuilder> builders = new ArrayList<IndexRequestBuilder>();
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
builders.add(client().prepareIndex("empty_bucket_idx", "type", "" + i).setSource(jsonBuilder() builders.add(client().prepareIndex("empty_bucket_idx", "type", "" + i).setSource(jsonBuilder()
.startObject() .startObject()
.field("value", i * 2) .field(SINGLE_VALUED_FIELD_NAME, i * 2)
.endObject())); .endObject()));
} }
indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()])); indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()]));
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx") SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
.setQuery(matchAllQuery()) .setQuery(matchAllQuery())
.addAggregation(histogram("histo").field("value").interval(1l).minDocCount(0) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(1l).minDocCount(0)
.subAggregation(range("range").addRange("0-2", 0.0, 2.0))) .subAggregation(range("range").addRange("0-2", 0.0, 2.0)))
.execute().actionGet(); .execute().actionGet();

View File

@ -57,6 +57,8 @@ import static org.hamcrest.core.IsNull.notNullValue;
*/ */
public class StringTermsTests extends ElasticsearchIntegrationTest { public class StringTermsTests extends ElasticsearchIntegrationTest {
private static final String SINGLE_VALUED_FIELD_NAME = "s_value";
private static final String MULTI_VALUED_FIELD_NAME = "s_values";
@Override @Override
public Settings indexSettings() { public Settings indexSettings() {
@ -77,9 +79,9 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
for (int i = 0; i < lowCardBuilders.length; i++) { for (int i = 0; i < lowCardBuilders.length; i++) {
lowCardBuilders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder() lowCardBuilders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder()
.startObject() .startObject()
.field("value", "val" + i) .field(SINGLE_VALUED_FIELD_NAME, "val" + i)
.field("i", i) .field("i", i)
.startArray("values").value("val" + i).value("val" + (i + 1)).endArray() .startArray(MULTI_VALUED_FIELD_NAME).value("val" + i).value("val" + (i + 1)).endArray()
.endObject()); .endObject());
} }
indexRandom(true, lowCardBuilders); indexRandom(true, lowCardBuilders);
@ -88,8 +90,8 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
for (int i = 0; i < highCardBuilders.length; i++) { for (int i = 0; i < highCardBuilders.length; i++) {
highCardBuilders[i] = client().prepareIndex("idx", "high_card_type").setSource(jsonBuilder() highCardBuilders[i] = client().prepareIndex("idx", "high_card_type").setSource(jsonBuilder()
.startObject() .startObject()
.field("value", "val" + Strings.padStart(i+"", 3, '0')) .field(SINGLE_VALUED_FIELD_NAME, "val" + Strings.padStart(i+"", 3, '0'))
.startArray("values").value("val" + Strings.padStart(i+"", 3, '0')).value("val" + Strings.padStart((i+1)+"", 3, '0')).endArray() .startArray(MULTI_VALUED_FIELD_NAME).value("val" + Strings.padStart(i+"", 3, '0')).value("val" + Strings.padStart((i+1)+"", 3, '0')).endArray()
.endObject()); .endObject());
} }
indexRandom(true, highCardBuilders); indexRandom(true, highCardBuilders);
@ -104,7 +106,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type") SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.minDocCount(minDocCount) .minDocCount(minDocCount)
.size(0)) .size(0))
.execute().actionGet(); .execute().actionGet();
@ -122,7 +124,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value")) .field(SINGLE_VALUED_FIELD_NAME))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -148,7 +150,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type") SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value").include("val00.+")) .field(SINGLE_VALUED_FIELD_NAME).include("val00.+"))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -170,7 +172,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
response = client().prepareSearch("idx").setTypes("high_card_type") response = client().prepareSearch("idx").setTypes("high_card_type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value").include("val00.+").exclude("(val000|val001)")) .field(SINGLE_VALUED_FIELD_NAME).include("val00.+").exclude("(val000|val001)"))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -192,7 +194,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
response = client().prepareSearch("idx").setTypes("high_card_type") response = client().prepareSearch("idx").setTypes("high_card_type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value").exclude("val0[1-9]+.+")) .field(SINGLE_VALUED_FIELD_NAME).exclude("val0[1-9]+.+"))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -219,7 +221,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type") SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value").include("VAL00.+", Pattern.CASE_INSENSITIVE)) .field(SINGLE_VALUED_FIELD_NAME).include("VAL00.+", Pattern.CASE_INSENSITIVE))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -242,7 +244,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
response = client().prepareSearch("idx").setTypes("high_card_type") response = client().prepareSearch("idx").setTypes("high_card_type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value").include("val00.+").exclude("( val000 | VAL001 )#this is a comment", Pattern.CASE_INSENSITIVE | Pattern.COMMENTS)) .field(SINGLE_VALUED_FIELD_NAME).include("val00.+").exclude("( val000 | VAL001 )#this is a comment", Pattern.CASE_INSENSITIVE | Pattern.COMMENTS))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -265,7 +267,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
response = client().prepareSearch("idx").setTypes("high_card_type") response = client().prepareSearch("idx").setTypes("high_card_type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.field("value").exclude("val0[1-9]+.+", 0)) .field(SINGLE_VALUED_FIELD_NAME).exclude("val0[1-9]+.+", 0))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -289,7 +291,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type") SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.size(20) .size(20)
.order(Terms.Order.term(true))) // we need to sort by terms cause we're checking the first 20 values .order(Terms.Order.term(true))) // we need to sort by terms cause we're checking the first 20 values
.execute().actionGet(); .execute().actionGet();
@ -314,7 +316,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.term(true))) .order(Terms.Order.term(true)))
.execute().actionGet(); .execute().actionGet();
@ -339,7 +341,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.term(false))) .order(Terms.Order.term(false)))
.execute().actionGet(); .execute().actionGet();
@ -364,8 +366,8 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.subAggregation(count("count").field("values"))) .subAggregation(count("count").field(MULTI_VALUED_FIELD_NAME)))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -391,7 +393,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.subAggregation(count("count"))) .subAggregation(count("count")))
.execute().actionGet(); .execute().actionGet();
@ -418,7 +420,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.script("'foo_' + _value")) .script("'foo_' + _value"))
.execute().actionGet(); .execute().actionGet();
@ -442,7 +444,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.script("_value.substring(0,3)")) .script("_value.substring(0,3)"))
.execute().actionGet(); .execute().actionGet();
@ -464,7 +466,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("values")) .field(MULTI_VALUED_FIELD_NAME))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -491,7 +493,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.script("'foo_' + _value")) .script("'foo_' + _value"))
.execute().actionGet(); .execute().actionGet();
@ -537,7 +539,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("values") .field(MULTI_VALUED_FIELD_NAME)
.script("'foo_' + _value") .script("'foo_' + _value")
.subAggregation(count("count"))) .subAggregation(count("count")))
.execute().actionGet(); .execute().actionGet();
@ -572,7 +574,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.script("doc['value'].value")) .script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value"))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -595,7 +597,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.script("doc['value'].value")) .script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value"))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -618,7 +620,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.script("doc['value'].value") .script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value")
.subAggregation(count("count"))) .subAggregation(count("count")))
.execute().actionGet(); .execute().actionGet();
@ -645,7 +647,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.script("doc['values'].values")) .script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values"))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -672,7 +674,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.script("doc['values'].values") .script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
.subAggregation(count("count"))) .subAggregation(count("count")))
.execute().actionGet(); .execute().actionGet();
@ -707,7 +709,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.size(randomInt(5)) .size(randomInt(5))
.field("value")) .field(SINGLE_VALUED_FIELD_NAME))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -723,7 +725,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx", "idx_unmapped").setTypes("type") SearchResponse response = client().prepareSearch("idx", "idx_unmapped").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value")) .field(SINGLE_VALUED_FIELD_NAME))
.execute().actionGet(); .execute().actionGet();
assertSearchResponse(response); assertSearchResponse(response);
@ -745,7 +747,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
public void stringTermsNestedIntoPerBucketAggregator() throws Exception { public void stringTermsNestedIntoPerBucketAggregator() throws Exception {
// no execution hint so that the logic that decides whether or not to use ordinals is executed // no execution hint so that the logic that decides whether or not to use ordinals is executed
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(filter("filter").filter(termFilter("values", "val3")).subAggregation(terms("terms").field("values"))) .addAggregation(filter("filter").filter(termFilter(MULTI_VALUED_FIELD_NAME, "val3")).subAggregation(terms("terms").field(MULTI_VALUED_FIELD_NAME)))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getFailedShards(), equalTo(0)); assertThat(response.getFailedShards(), equalTo(0));
@ -767,19 +769,19 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
@Test @Test
public void emptyAggregation() throws Exception { public void emptyAggregation() throws Exception {
prepareCreate("empty_bucket_idx").addMapping("type", "value", "type=integer").execute().actionGet(); prepareCreate("empty_bucket_idx").addMapping("type", SINGLE_VALUED_FIELD_NAME, "type=integer").execute().actionGet();
List<IndexRequestBuilder> builders = new ArrayList<IndexRequestBuilder>(); List<IndexRequestBuilder> builders = new ArrayList<IndexRequestBuilder>();
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
builders.add(client().prepareIndex("empty_bucket_idx", "type", ""+i).setSource(jsonBuilder() builders.add(client().prepareIndex("empty_bucket_idx", "type", ""+i).setSource(jsonBuilder()
.startObject() .startObject()
.field("value", i*2) .field(SINGLE_VALUED_FIELD_NAME, i*2)
.endObject())); .endObject()));
} }
indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()])); indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()]));
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx") SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
.setQuery(matchAllQuery()) .setQuery(matchAllQuery())
.addAggregation(histogram("histo").field("value").interval(1l).minDocCount(0) .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(1l).minDocCount(0)
.subAggregation(terms("terms"))) .subAggregation(terms("terms")))
.execute().actionGet(); .execute().actionGet();
@ -801,7 +803,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("avg_i", asc)) .order(Terms.Order.aggregation("avg_i", asc))
.subAggregation(avg("avg_i").field("i")) .subAggregation(avg("avg_i").field("i"))
).execute().actionGet(); ).execute().actionGet();
@ -833,7 +835,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
client().prepareSearch("idx").setTypes("type") client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("avg_i", true)) .order(Terms.Order.aggregation("avg_i", true))
).execute().actionGet(); ).execute().actionGet();
@ -852,7 +854,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
client().prepareSearch("idx").setTypes("type") client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("filter", true)) .order(Terms.Order.aggregation("filter", true))
.subAggregation(filter("filter").filter(FilterBuilders.termFilter("foo", "bar"))) .subAggregation(filter("filter").filter(FilterBuilders.termFilter("foo", "bar")))
).execute().actionGet(); ).execute().actionGet();
@ -872,7 +874,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
client().prepareSearch("idx").setTypes("type") client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats.foo", true)) .order(Terms.Order.aggregation("stats.foo", true))
.subAggregation(stats("stats").field("i")) .subAggregation(stats("stats").field("i"))
).execute().actionGet(); ).execute().actionGet();
@ -893,7 +895,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
client().prepareSearch("idx").setTypes("type") client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats", true)) .order(Terms.Order.aggregation("stats", true))
.subAggregation(stats("stats").field("i")) .subAggregation(stats("stats").field("i"))
).execute().actionGet(); ).execute().actionGet();
@ -912,7 +914,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("avg_i", asc)) .order(Terms.Order.aggregation("avg_i", asc))
.subAggregation(avg("avg_i").field("i")) .subAggregation(avg("avg_i").field("i"))
).execute().actionGet(); ).execute().actionGet();
@ -945,7 +947,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats.avg", asc)) .order(Terms.Order.aggregation("stats.avg", asc))
.subAggregation(stats("stats").field("i")) .subAggregation(stats("stats").field("i"))
).execute().actionGet(); ).execute().actionGet();
@ -976,7 +978,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats.avg", asc)) .order(Terms.Order.aggregation("stats.avg", asc))
.subAggregation(stats("stats").field("i")) .subAggregation(stats("stats").field("i"))
).execute().actionGet(); ).execute().actionGet();
@ -1007,7 +1009,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("idx").setTypes("type") SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(terms("terms") .addAggregation(terms("terms")
.executionHint(randomExecutionHint()) .executionHint(randomExecutionHint())
.field("value") .field(SINGLE_VALUED_FIELD_NAME)
.order(Terms.Order.aggregation("stats.variance", asc)) .order(Terms.Order.aggregation("stats.variance", asc))
.subAggregation(extendedStats("stats").field("i")) .subAggregation(extendedStats("stats").field("i"))
).execute().actionGet(); ).execute().actionGet();