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:
parent
663e25ae63
commit
9d10c2fca8
|
@ -52,6 +52,8 @@ import static org.hamcrest.core.IsNull.notNullValue;
|
|||
public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
||||
|
||||
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
|
||||
public Settings indexSettings() {
|
||||
|
@ -69,8 +71,8 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
for (int i = 0; i < lowcardBuilders.length; i++) {
|
||||
lowcardBuilders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", (double) i)
|
||||
.startArray("values").value((double)i).value(i + 1d).endArray()
|
||||
.field(SINGLE_VALUED_FIELD_NAME, (double) i)
|
||||
.startArray(MULTI_VALUED_FIELD_NAME).value((double)i).value(i + 1d).endArray()
|
||||
.endObject());
|
||||
|
||||
}
|
||||
|
@ -79,8 +81,8 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
for (int i = 0; i < highCardBuilders.length; i++) {
|
||||
highCardBuilders[i] = client().prepareIndex("idx", "high_card_type").setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", (double) i)
|
||||
.startArray("values").value((double)i).value(i + 1d).endArray()
|
||||
.field(SINGLE_VALUED_FIELD_NAME, (double) i)
|
||||
.startArray(MULTI_VALUED_FIELD_NAME).value((double)i).value(i + 1d).endArray()
|
||||
.endObject());
|
||||
}
|
||||
indexRandom(true, highCardBuilders);
|
||||
|
@ -94,7 +96,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void sizeIsZero() {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.minDocCount(randomInt(1))
|
||||
.size(0))
|
||||
.execute().actionGet();
|
||||
|
@ -111,7 +113,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValueField() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value"))
|
||||
.field(SINGLE_VALUED_FIELD_NAME))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -135,7 +137,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValueField_WithMaxSize() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.size(20)
|
||||
.order(Terms.Order.term(true))) // we need to sort by terms cause we're checking the first 20 values
|
||||
.execute().actionGet();
|
||||
|
@ -161,7 +163,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValueField_OrderedByTermAsc() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.term(true)))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -187,7 +189,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValueField_OrderedByTermDesc() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.term(false)))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -213,8 +215,8 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValuedField_WithSubAggregation() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.subAggregation(sum("sum").field("values")))
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.subAggregation(sum("sum").field(MULTI_VALUED_FIELD_NAME)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -241,7 +243,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValuedField_WithSubAggregation_Inherited() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.subAggregation(sum("sum")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -269,7 +271,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValuedField_WithValueScript() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.script("_value + 1"))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -294,7 +296,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void multiValuedField() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("values"))
|
||||
.field(MULTI_VALUED_FIELD_NAME))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -322,7 +324,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void multiValuedField_WithValueScript() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script("_value + 1"))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -351,7 +353,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void multiValuedField_WithValueScript_NotUnique() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script("(long) _value / 1000 + 1"))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -391,7 +393,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script("_value + 1")
|
||||
.subAggregation(sum("sum")))
|
||||
.execute().actionGet();
|
||||
|
@ -428,7 +430,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void script_SingleValue() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.script("doc['value'].value"))
|
||||
.script("doc['" + MULTI_VALUED_FIELD_NAME + "'].value"))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -452,7 +454,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void script_SingleValue_WithSubAggregator_Inherited() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.subAggregation(sum("sum")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -480,7 +482,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void script_MultiValued() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.script("doc['values'].values"))
|
||||
.script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values"))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -514,7 +516,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.script("doc['values'].values")
|
||||
.script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
|
||||
.subAggregation(sum("sum")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -531,7 +533,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void script_MultiValued_WithAggregatorInherited_WithExplicitType() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.script("doc['values'].values")
|
||||
.script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
|
||||
.valueType(Terms.ValueType.DOUBLE)
|
||||
.subAggregation(sum("sum")))
|
||||
.execute().actionGet();
|
||||
|
@ -568,7 +570,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void unmapped() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.size(randomInt(5)))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -585,7 +587,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void partiallyUnmapped() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value"))
|
||||
.field(SINGLE_VALUED_FIELD_NAME))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -607,19 +609,19 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
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>();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
builders.add(client().prepareIndex("empty_bucket_idx", "type", ""+i).setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", i*2)
|
||||
.field(SINGLE_VALUED_FIELD_NAME, i*2)
|
||||
.endObject()));
|
||||
}
|
||||
indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()]));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
|
||||
.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")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -640,9 +642,9 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
boolean asc = true;
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("avg_i", asc))
|
||||
.subAggregation(avg("avg_i").field("value"))
|
||||
.subAggregation(avg("avg_i").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
|
||||
|
@ -671,7 +673,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("avg_i", true))
|
||||
).execute().actionGet();
|
||||
|
||||
|
@ -689,7 +691,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("filter", true))
|
||||
.subAggregation(filter("filter").filter(FilterBuilders.termFilter("foo", "bar")))
|
||||
).execute().actionGet();
|
||||
|
@ -708,9 +710,9 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.foo", true))
|
||||
.subAggregation(stats("stats").field("value"))
|
||||
.subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
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")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats", true))
|
||||
.subAggregation(stats("stats").field("value"))
|
||||
.subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
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;
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("avg_i", asc))
|
||||
.subAggregation(avg("avg_i").field("value"))
|
||||
.subAggregation(avg("avg_i").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
|
||||
|
@ -778,9 +780,9 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
boolean asc = true;
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.avg", asc))
|
||||
.subAggregation(stats("stats").field("value"))
|
||||
.subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -808,9 +810,9 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
boolean asc = false;
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.avg", asc))
|
||||
.subAggregation(stats("stats").field("value"))
|
||||
.subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -838,9 +840,9 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
boolean asc = true;
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.variance", asc))
|
||||
.subAggregation(extendedStats("stats").field("value"))
|
||||
.subAggregation(extendedStats("stats").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
|
|
@ -48,6 +48,9 @@ import static org.hamcrest.core.IsNull.notNullValue;
|
|||
*/
|
||||
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
|
||||
public Settings indexSettings() {
|
||||
return ImmutableSettings.builder()
|
||||
|
@ -92,8 +95,8 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
for (int i = 0; i < builders.length; i++) {
|
||||
builders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", i + 1)
|
||||
.startArray("values").value(i + 1).value(i + 2).endArray()
|
||||
.field(SINGLE_VALUED_FIELD_NAME, i + 1)
|
||||
.startArray(MULTI_VALUED_FIELD_NAME).value(i + 1).value(i + 2).endArray()
|
||||
.field("tag", "tag" + i)
|
||||
.endObject());
|
||||
}
|
||||
|
@ -104,7 +107,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void singleValuedField() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(histogram("histo").field("value").interval(interval))
|
||||
.addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -126,7 +129,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void singleValuedField_OrderedByKeyAsc() throws Exception {
|
||||
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();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -148,7 +151,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void singleValuedField_OrderedByKeyDesc() throws Exception {
|
||||
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();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -170,7 +173,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void singleValuedField_OrderedByCountAsc() throws Exception {
|
||||
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();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -198,7 +201,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void singleValuedField_OrderedByCountDesc() throws Exception {
|
||||
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();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -226,8 +229,8 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void singleValuedField_WithSubAggregation() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(histogram("histo").field("value").interval(interval)
|
||||
.subAggregation(sum("sum").field("value")))
|
||||
.addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval)
|
||||
.subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -259,7 +262,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void singleValuedField_WithSubAggregation_Inherited() throws Exception {
|
||||
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")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -292,8 +295,8 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void singleValuedField_OrderedBySubAggregationAsc() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(histogram("histo").field("value").interval(interval).order(Histogram.Order.aggregation("sum", true))
|
||||
.subAggregation(sum("sum").field("value")))
|
||||
.addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.aggregation("sum", true))
|
||||
.subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -331,8 +334,8 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void singleValuedField_OrderedBySubAggregationDesc() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(histogram("histo").field("value").interval(interval).order(Histogram.Order.aggregation("sum", false))
|
||||
.subAggregation(sum("sum").field("value")))
|
||||
.addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.aggregation("sum", false))
|
||||
.subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -370,7 +373,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void singleValuedField_OrderedByMultiValuedSubAggregationAsc_Inherited() throws Exception {
|
||||
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")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -409,8 +412,8 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void singleValuedField_OrderedByMultiValuedSubAggregationDesc() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(histogram("histo").field("value").interval(interval).order(Histogram.Order.aggregation("stats.sum", false))
|
||||
.subAggregation(stats("stats").field("value")))
|
||||
.addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.aggregation("stats.sum", false))
|
||||
.subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -448,7 +451,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void singleValuedField_WithValueScript() throws Exception {
|
||||
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();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -476,7 +479,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void multiValuedField() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(histogram("histo").field("values").interval(interval))
|
||||
.addAggregation(histogram("histo").field(MULTI_VALUED_FIELD_NAME).interval(interval))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -498,7 +501,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void multiValuedField_OrderedByKeyDesc() throws Exception {
|
||||
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();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -520,7 +523,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void multiValuedField_WithValueScript() throws Exception {
|
||||
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();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -553,8 +556,8 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(histogram("histo").field("values").script("_value + 1").interval(interval)
|
||||
.subAggregation(terms("values").order(Terms.Order.term(true))))
|
||||
.addAggregation(histogram("histo").field(MULTI_VALUED_FIELD_NAME).script("_value + 1").interval(interval)
|
||||
.subAggregation(terms(MULTI_VALUED_FIELD_NAME).order(Terms.Order.term(true))))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -581,9 +584,9 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(bucket, notNullValue());
|
||||
assertThat(bucket.getKey(), equalTo((long) i * interval));
|
||||
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.getName(), equalTo("values"));
|
||||
assertThat(terms.getName(), equalTo(MULTI_VALUED_FIELD_NAME));
|
||||
int minTerm = Math.max(2, i * interval - 1);
|
||||
int maxTerm = Math.min(numDocs + 2, (i + 1) * interval);
|
||||
assertThat(terms.buckets().size(), equalTo(maxTerm - minTerm + 1));
|
||||
|
@ -597,7 +600,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void script_SingleValue() throws Exception {
|
||||
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();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -619,7 +622,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void script_SingleValue_WithSubAggregator_Inherited() throws Exception {
|
||||
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")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -652,7 +655,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void script_MultiValued() throws Exception {
|
||||
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();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -674,7 +677,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void script_MultiValued_WithAggregatorInherited() throws Exception {
|
||||
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")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -708,7 +711,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void unmapped() throws Exception {
|
||||
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();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -723,7 +726,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void partiallyUnmapped() throws Exception {
|
||||
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();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -744,19 +747,19 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
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>();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
builders.add(client().prepareIndex("empty_bucket_idx", "type", "" + i).setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", i * 2)
|
||||
.field(SINGLE_VALUED_FIELD_NAME, i * 2)
|
||||
.endObject()));
|
||||
}
|
||||
indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()]));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
|
||||
.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)))
|
||||
.execute().actionGet();
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ import static org.hamcrest.core.IsNull.notNullValue;
|
|||
public class LongTermsTests extends ElasticsearchIntegrationTest {
|
||||
|
||||
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
|
||||
public Settings indexSettings() {
|
||||
|
@ -68,8 +70,8 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
for (int i = 0; i < lowCardBuilders.length; i++) {
|
||||
lowCardBuilders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", i)
|
||||
.startArray("values").value(i).value(i + 1).endArray()
|
||||
.field(SINGLE_VALUED_FIELD_NAME, i)
|
||||
.startArray(MULTI_VALUED_FIELD_NAME).value(i).value(i + 1).endArray()
|
||||
.endObject());
|
||||
}
|
||||
indexRandom(randomBoolean(), lowCardBuilders);
|
||||
|
@ -77,8 +79,8 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
for (int i = 0; i < highCardBuilders.length; i++) {
|
||||
highCardBuilders[i] = client().prepareIndex("idx", "high_card_type").setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", i)
|
||||
.startArray("values").value(i).value(i + 1).endArray()
|
||||
.field(SINGLE_VALUED_FIELD_NAME, i)
|
||||
.startArray(MULTI_VALUED_FIELD_NAME).value(i).value(i + 1).endArray()
|
||||
.endObject());
|
||||
|
||||
}
|
||||
|
@ -92,7 +94,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void sizeIsZero() {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.minDocCount(randomInt(1))
|
||||
.size(0))
|
||||
.execute().actionGet();
|
||||
|
@ -109,7 +111,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValueField() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value"))
|
||||
.field(SINGLE_VALUED_FIELD_NAME))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -133,7 +135,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValueField_WithMaxSize() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.size(20)
|
||||
.order(Terms.Order.term(true))) // we need to sort by terms cause we're checking the first 20 values
|
||||
.execute().actionGet();
|
||||
|
@ -159,7 +161,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValueField_OrderedByTermAsc() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.term(true)))
|
||||
.execute().actionGet();
|
||||
assertSearchResponse(response);
|
||||
|
@ -183,7 +185,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValueField_OrderedByTermDesc() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.term(false)))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -209,8 +211,8 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValuedField_WithSubAggregation() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.subAggregation(sum("sum").field("values")))
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.subAggregation(sum("sum").field(MULTI_VALUED_FIELD_NAME)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -237,7 +239,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValuedField_WithSubAggregation_Inherited() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.subAggregation(sum("sum")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -265,7 +267,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValuedField_WithValueScript() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.script("_value + 1"))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -290,7 +292,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void multiValuedField() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("values"))
|
||||
.field(MULTI_VALUED_FIELD_NAME))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -318,7 +320,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void multiValuedField_WithValueScript() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script("_value - 1"))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -347,7 +349,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void multiValuedField_WithValueScript_NotUnique() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script("floor(_value / 1000 + 1)"))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -387,7 +389,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script("_value + 1")
|
||||
.subAggregation(sum("sum")))
|
||||
.execute().actionGet();
|
||||
|
@ -424,7 +426,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void script_SingleValue() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.script("doc['value'].value"))
|
||||
.script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value"))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -448,7 +450,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void script_SingleValue_WithSubAggregator_Inherited() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.subAggregation(sum("sum")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -476,7 +478,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void script_MultiValued() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.script("doc['values'].values"))
|
||||
.script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values"))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -510,7 +512,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.script("doc['values'].values")
|
||||
.script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
|
||||
.subAggregation(sum("sum")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -525,7 +527,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void script_MultiValued_WithAggregatorInherited_WithExplicitType() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.script("doc['values'].values")
|
||||
.script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
|
||||
.valueType(Terms.ValueType.LONG)
|
||||
.subAggregation(sum("sum")))
|
||||
.execute().actionGet();
|
||||
|
@ -562,7 +564,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void unmapped() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.size(randomInt(5)))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -579,7 +581,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void partiallyUnmapped() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value"))
|
||||
.field(SINGLE_VALUED_FIELD_NAME))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -601,19 +603,19 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
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>();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
builders.add(client().prepareIndex("empty_bucket_idx", "type", ""+i).setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", i*2)
|
||||
.field(SINGLE_VALUED_FIELD_NAME, i*2)
|
||||
.endObject()));
|
||||
}
|
||||
indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()]));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
|
||||
.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")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -634,9 +636,9 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
boolean asc = true;
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("avg_i", asc))
|
||||
.subAggregation(avg("avg_i").field("value"))
|
||||
.subAggregation(avg("avg_i").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
|
||||
|
@ -665,7 +667,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("avg_i", true))
|
||||
).execute().actionGet();
|
||||
|
||||
|
@ -683,7 +685,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("filter", true))
|
||||
.subAggregation(filter("filter").filter(FilterBuilders.termFilter("foo", "bar")))
|
||||
).execute().actionGet();
|
||||
|
@ -702,9 +704,9 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.foo", true))
|
||||
.subAggregation(stats("stats").field("value"))
|
||||
.subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
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")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats", true))
|
||||
.subAggregation(stats("stats").field("value"))
|
||||
.subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
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;
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("avg_i", asc))
|
||||
.subAggregation(avg("avg_i").field("value"))
|
||||
.subAggregation(avg("avg_i").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
|
||||
|
@ -772,9 +774,9 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
boolean asc = true;
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.avg", asc))
|
||||
.subAggregation(stats("stats").field("value"))
|
||||
.subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -802,9 +804,9 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
boolean asc = false;
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.avg", asc))
|
||||
.subAggregation(stats("stats").field("value"))
|
||||
.subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -832,9 +834,9 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
boolean asc = true;
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.variance", asc))
|
||||
.subAggregation(extendedStats("stats").field("value"))
|
||||
.subAggregation(extendedStats("stats").field(SINGLE_VALUED_FIELD_NAME))
|
||||
).execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
|
|
@ -48,6 +48,8 @@ import static org.hamcrest.core.IsNull.notNullValue;
|
|||
*/
|
||||
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
|
||||
public Settings indexSettings() {
|
||||
|
@ -67,8 +69,8 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
for (int i = 0; i < builders.length; i++) {
|
||||
builders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", i+1)
|
||||
.startArray("values").value(i+1).value(i+2).endArray()
|
||||
.field(SINGLE_VALUED_FIELD_NAME, i+1)
|
||||
.startArray(MULTI_VALUED_FIELD_NAME).value(i+1).value(i+2).endArray()
|
||||
.endObject());
|
||||
}
|
||||
indexRandom(true, builders);
|
||||
|
@ -79,8 +81,8 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void rangeAsSubAggregation() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(terms("terms").field("values").size(100).subAggregation(
|
||||
range("range").field("value")
|
||||
.addAggregation(terms("terms").field(MULTI_VALUED_FIELD_NAME).size(100).subAggregation(
|
||||
range("range").field(SINGLE_VALUED_FIELD_NAME)
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
.addUnboundedFrom(6)))
|
||||
|
@ -130,7 +132,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValueField() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
.addUnboundedFrom(6))
|
||||
|
@ -170,7 +172,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValueField_WithCustomKey() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.addUnboundedTo("r1", 3)
|
||||
.addRange("r2", 3, 6)
|
||||
.addUnboundedFrom("r3", 6))
|
||||
|
@ -210,11 +212,11 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValuedField_WithSubAggregation() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
.addUnboundedFrom(6)
|
||||
.subAggregation(sum("sum").field("value")))
|
||||
.subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -264,7 +266,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValuedField_WithSubAggregation_Inherited() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
.addUnboundedFrom(6)
|
||||
|
@ -318,7 +320,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void singleValuedField_WithValueScript() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.script("_value + 1")
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
|
@ -372,7 +374,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void multiValuedField() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
.addUnboundedFrom(6))
|
||||
|
@ -425,7 +427,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void multiValuedField_WithValueScript() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script("_value + 1")
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
|
@ -483,7 +485,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script("_value + 1")
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
|
@ -541,7 +543,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void script_SingleValue() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.script("doc['value'].value")
|
||||
.script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value")
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
.addUnboundedFrom(6))
|
||||
|
@ -581,7 +583,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void script_SingleValue_WithSubAggregator_Inherited() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.script("doc['value'].value")
|
||||
.script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value")
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
.addUnboundedFrom(6)
|
||||
|
@ -635,7 +637,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void emptyRange() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.addUnboundedTo(-1)
|
||||
.addUnboundedFrom(1000))
|
||||
.execute().actionGet();
|
||||
|
@ -667,7 +669,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void script_MultiValued() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.script("doc['values'].values")
|
||||
.script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
.addUnboundedFrom(6))
|
||||
|
@ -724,7 +726,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void script_MultiValued_WithAggregatorInherited() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.script("doc['values'].values")
|
||||
.script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
|
||||
.addUnboundedTo("r1", 3)
|
||||
.addRange("r2", 3, 6)
|
||||
.addUnboundedFrom("r3", 6)
|
||||
|
@ -781,7 +783,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void unmapped() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped")
|
||||
.addAggregation(range("range")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
.addUnboundedFrom(6))
|
||||
|
@ -823,7 +825,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
|
||||
.addAggregation(range("range")
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.addUnboundedTo(3)
|
||||
.addRange(3, 6)
|
||||
.addUnboundedFrom(6))
|
||||
|
@ -863,7 +865,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
public void overlappingRanges() throws Exception {
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(range("range")
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.addUnboundedTo(5)
|
||||
.addRange(3, 6)
|
||||
.addRange(4, 5)
|
||||
|
@ -909,19 +911,19 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
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>();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
builders.add(client().prepareIndex("empty_bucket_idx", "type", "" + i).setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", i * 2)
|
||||
.field(SINGLE_VALUED_FIELD_NAME, i * 2)
|
||||
.endObject()));
|
||||
}
|
||||
indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()]));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
|
||||
.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)))
|
||||
.execute().actionGet();
|
||||
|
||||
|
|
|
@ -57,6 +57,8 @@ import static org.hamcrest.core.IsNull.notNullValue;
|
|||
*/
|
||||
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
|
||||
public Settings indexSettings() {
|
||||
|
@ -77,9 +79,9 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
for (int i = 0; i < lowCardBuilders.length; i++) {
|
||||
lowCardBuilders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", "val" + i)
|
||||
.field(SINGLE_VALUED_FIELD_NAME, "val" + 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());
|
||||
}
|
||||
indexRandom(true, lowCardBuilders);
|
||||
|
@ -88,8 +90,8 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
for (int i = 0; i < highCardBuilders.length; i++) {
|
||||
highCardBuilders[i] = client().prepareIndex("idx", "high_card_type").setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", "val" + Strings.padStart(i+"", 3, '0'))
|
||||
.startArray("values").value("val" + Strings.padStart(i+"", 3, '0')).value("val" + Strings.padStart((i+1)+"", 3, '0')).endArray()
|
||||
.field(SINGLE_VALUED_FIELD_NAME, "val" + Strings.padStart(i+"", 3, '0'))
|
||||
.startArray(MULTI_VALUED_FIELD_NAME).value("val" + Strings.padStart(i+"", 3, '0')).value("val" + Strings.padStart((i+1)+"", 3, '0')).endArray()
|
||||
.endObject());
|
||||
}
|
||||
indexRandom(true, highCardBuilders);
|
||||
|
@ -104,7 +106,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.minDocCount(minDocCount)
|
||||
.size(0))
|
||||
.execute().actionGet();
|
||||
|
@ -122,7 +124,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value"))
|
||||
.field(SINGLE_VALUED_FIELD_NAME))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -148,7 +150,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value").include("val00.+"))
|
||||
.field(SINGLE_VALUED_FIELD_NAME).include("val00.+"))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -170,7 +172,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
response = client().prepareSearch("idx").setTypes("high_card_type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value").include("val00.+").exclude("(val000|val001)"))
|
||||
.field(SINGLE_VALUED_FIELD_NAME).include("val00.+").exclude("(val000|val001)"))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -192,7 +194,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
response = client().prepareSearch("idx").setTypes("high_card_type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value").exclude("val0[1-9]+.+"))
|
||||
.field(SINGLE_VALUED_FIELD_NAME).exclude("val0[1-9]+.+"))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -219,7 +221,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value").include("VAL00.+", Pattern.CASE_INSENSITIVE))
|
||||
.field(SINGLE_VALUED_FIELD_NAME).include("VAL00.+", Pattern.CASE_INSENSITIVE))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -242,7 +244,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
response = client().prepareSearch("idx").setTypes("high_card_type")
|
||||
.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();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -265,7 +267,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
response = client().prepareSearch("idx").setTypes("high_card_type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value").exclude("val0[1-9]+.+", 0))
|
||||
.field(SINGLE_VALUED_FIELD_NAME).exclude("val0[1-9]+.+", 0))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -289,7 +291,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.size(20)
|
||||
.order(Terms.Order.term(true))) // we need to sort by terms cause we're checking the first 20 values
|
||||
.execute().actionGet();
|
||||
|
@ -314,7 +316,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.term(true)))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -339,7 +341,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.term(false)))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -364,8 +366,8 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.subAggregation(count("count").field("values")))
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.subAggregation(count("count").field(MULTI_VALUED_FIELD_NAME)))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -391,7 +393,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.subAggregation(count("count")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -418,7 +420,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.script("'foo_' + _value"))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -442,7 +444,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script("_value.substring(0,3)"))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -464,7 +466,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("values"))
|
||||
.field(MULTI_VALUED_FIELD_NAME))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -491,7 +493,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script("'foo_' + _value"))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -537,7 +539,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("values")
|
||||
.field(MULTI_VALUED_FIELD_NAME)
|
||||
.script("'foo_' + _value")
|
||||
.subAggregation(count("count")))
|
||||
.execute().actionGet();
|
||||
|
@ -572,7 +574,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.script("doc['value'].value"))
|
||||
.script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value"))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -595,7 +597,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.script("doc['value'].value"))
|
||||
.script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value"))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -618,7 +620,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.script("doc['value'].value")
|
||||
.script("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value")
|
||||
.subAggregation(count("count")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -645,7 +647,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.script("doc['values'].values"))
|
||||
.script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values"))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -672,7 +674,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.script("doc['values'].values")
|
||||
.script("doc['" + MULTI_VALUED_FIELD_NAME + "'].values")
|
||||
.subAggregation(count("count")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -707,7 +709,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.size(randomInt(5))
|
||||
.field("value"))
|
||||
.field(SINGLE_VALUED_FIELD_NAME))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -723,7 +725,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx", "idx_unmapped").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value"))
|
||||
.field(SINGLE_VALUED_FIELD_NAME))
|
||||
.execute().actionGet();
|
||||
|
||||
assertSearchResponse(response);
|
||||
|
@ -745,7 +747,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
public void stringTermsNestedIntoPerBucketAggregator() throws Exception {
|
||||
// no execution hint so that the logic that decides whether or not to use ordinals is executed
|
||||
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();
|
||||
|
||||
assertThat(response.getFailedShards(), equalTo(0));
|
||||
|
@ -767,19 +769,19 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
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>();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
builders.add(client().prepareIndex("empty_bucket_idx", "type", ""+i).setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field("value", i*2)
|
||||
.field(SINGLE_VALUED_FIELD_NAME, i*2)
|
||||
.endObject()));
|
||||
}
|
||||
indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()]));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
|
||||
.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")))
|
||||
.execute().actionGet();
|
||||
|
||||
|
@ -801,7 +803,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("avg_i", asc))
|
||||
.subAggregation(avg("avg_i").field("i"))
|
||||
).execute().actionGet();
|
||||
|
@ -833,7 +835,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("avg_i", true))
|
||||
).execute().actionGet();
|
||||
|
||||
|
@ -852,7 +854,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("filter", true))
|
||||
.subAggregation(filter("filter").filter(FilterBuilders.termFilter("foo", "bar")))
|
||||
).execute().actionGet();
|
||||
|
@ -872,7 +874,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.foo", true))
|
||||
.subAggregation(stats("stats").field("i"))
|
||||
).execute().actionGet();
|
||||
|
@ -893,7 +895,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats", true))
|
||||
.subAggregation(stats("stats").field("i"))
|
||||
).execute().actionGet();
|
||||
|
@ -912,7 +914,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("avg_i", asc))
|
||||
.subAggregation(avg("avg_i").field("i"))
|
||||
).execute().actionGet();
|
||||
|
@ -945,7 +947,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.avg", asc))
|
||||
.subAggregation(stats("stats").field("i"))
|
||||
).execute().actionGet();
|
||||
|
@ -976,7 +978,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.avg", asc))
|
||||
.subAggregation(stats("stats").field("i"))
|
||||
).execute().actionGet();
|
||||
|
@ -1007,7 +1009,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.executionHint(randomExecutionHint())
|
||||
.field("value")
|
||||
.field(SINGLE_VALUED_FIELD_NAME)
|
||||
.order(Terms.Order.aggregation("stats.variance", asc))
|
||||
.subAggregation(extendedStats("stats").field("i"))
|
||||
).execute().actionGet();
|
||||
|
|
Loading…
Reference in New Issue