|
@@ -30,6 +30,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
|
+import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.elasticsearch.index.query.QueryShardException;
|
|
|
import org.elasticsearch.plugins.Plugin;
|
|
@@ -38,6 +39,7 @@ import org.elasticsearch.script.MockScriptPlugin;
|
|
|
import org.elasticsearch.script.Script;
|
|
|
import org.elasticsearch.script.ScriptType;
|
|
|
import org.elasticsearch.search.aggregations.Aggregation;
|
|
|
+import org.elasticsearch.search.aggregations.AggregationBuilder;
|
|
|
import org.elasticsearch.search.aggregations.Aggregations;
|
|
|
import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter;
|
|
|
import org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms;
|
|
@@ -543,6 +545,37 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * A simple test that adds a sub-aggregation to a significant terms aggregation,
|
|
|
+ * to help check that sub-aggregation collection is handled correctly.
|
|
|
+ */
|
|
|
+ public void testSubAggregations() throws Exception {
|
|
|
+ indexEqualTestData();
|
|
|
+
|
|
|
+ QueryBuilder query = QueryBuilders.termsQuery(TEXT_FIELD, "a", "b");
|
|
|
+ AggregationBuilder subAgg = terms("class").field(CLASS_FIELD);
|
|
|
+ AggregationBuilder agg = significantTerms("significant_terms")
|
|
|
+ .field(TEXT_FIELD)
|
|
|
+ .executionHint(randomExecutionHint())
|
|
|
+ .significanceHeuristic(new ChiSquare(true, true))
|
|
|
+ .minDocCount(1).shardSize(1000).size(1000)
|
|
|
+ .subAggregation(subAgg);
|
|
|
+
|
|
|
+ SearchResponse response = client().prepareSearch("test")
|
|
|
+ .setQuery(query)
|
|
|
+ .addAggregation(agg)
|
|
|
+ .get();
|
|
|
+ assertSearchResponse(response);
|
|
|
+
|
|
|
+ SignificantTerms sigTerms = response.getAggregations().get("significant_terms");
|
|
|
+ assertThat(sigTerms.getBuckets().size(), equalTo(2));
|
|
|
+
|
|
|
+ for (SignificantTerms.Bucket bucket : sigTerms) {
|
|
|
+ StringTerms terms = bucket.getAggregations().get("class");
|
|
|
+ assertThat(terms.getBuckets().size(), equalTo(2));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void indexEqualTestData() throws ExecutionException, InterruptedException {
|
|
|
assertAcked(prepareCreate("test")
|
|
|
.setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0))
|