Terms aggs: Validate the aggregation order on unmapped terms too.
Close #8946
This commit is contained in:
parent
b2ec19ab36
commit
a50e3930c9
|
@ -31,8 +31,12 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public abstract class NonCollectingAggregator extends Aggregator {
|
public abstract class NonCollectingAggregator extends Aggregator {
|
||||||
|
|
||||||
|
protected NonCollectingAggregator(String name, AggregationContext context, Aggregator parent, AggregatorFactories subFactories, Map<String, Object> metaData) {
|
||||||
|
super(name, BucketAggregationMode.MULTI_BUCKETS, subFactories, 0, context, parent, metaData);
|
||||||
|
}
|
||||||
|
|
||||||
protected NonCollectingAggregator(String name, AggregationContext context, Aggregator parent, Map<String, Object> metaData) {
|
protected NonCollectingAggregator(String name, AggregationContext context, Aggregator parent, Map<String, Object> metaData) {
|
||||||
super(name, BucketAggregationMode.MULTI_BUCKETS, AggregatorFactories.EMPTY, 0, context, parent, metaData);
|
this(name, context, parent, AggregatorFactories.EMPTY, metaData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fail() {
|
private void fail() {
|
||||||
|
|
|
@ -147,7 +147,11 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory<Values
|
||||||
@Override
|
@Override
|
||||||
protected Aggregator createUnmapped(AggregationContext aggregationContext, Aggregator parent, Map<String, Object> metaData) {
|
protected Aggregator createUnmapped(AggregationContext aggregationContext, Aggregator parent, Map<String, Object> metaData) {
|
||||||
final InternalAggregation aggregation = new UnmappedTerms(name, order, bucketCountThresholds.getRequiredSize(), bucketCountThresholds.getShardSize(), bucketCountThresholds.getMinDocCount(), metaData);
|
final InternalAggregation aggregation = new UnmappedTerms(name, order, bucketCountThresholds.getRequiredSize(), bucketCountThresholds.getShardSize(), bucketCountThresholds.getMinDocCount(), metaData);
|
||||||
return new NonCollectingAggregator(name, aggregationContext, parent, metaData) {
|
return new NonCollectingAggregator(name, aggregationContext, parent, factories, metaData) {
|
||||||
|
{
|
||||||
|
// even in the case of an unmapped aggregator, validate the order
|
||||||
|
InternalOrder.validate(order, this);
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation buildEmptyAggregation() {
|
public InternalAggregation buildEmptyAggregation() {
|
||||||
return aggregation;
|
return aggregation;
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -983,9 +984,9 @@ public class DoubleTermsTests extends AbstractTermsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedByMissingSubAggregation() throws Exception {
|
public void singleValuedField_OrderedByMissingSubAggregation() throws Exception {
|
||||||
|
for (String index : Arrays.asList("idx", "idx_unmapped")) {
|
||||||
try {
|
try {
|
||||||
|
client().prepareSearch(index).setTypes("type")
|
||||||
client().prepareSearch("idx").setTypes("type")
|
|
||||||
.addAggregation(terms("terms")
|
.addAggregation(terms("terms")
|
||||||
.field(SINGLE_VALUED_FIELD_NAME)
|
.field(SINGLE_VALUED_FIELD_NAME)
|
||||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||||
|
@ -998,12 +999,13 @@ public class DoubleTermsTests extends AbstractTermsTests {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedByNonMetricsOrMultiBucketSubAggregation() throws Exception {
|
public void singleValuedField_OrderedByNonMetricsOrMultiBucketSubAggregation() throws Exception {
|
||||||
|
for (String index : Arrays.asList("idx", "idx_unmapped")) {
|
||||||
try {
|
try {
|
||||||
|
client().prepareSearch(index).setTypes("type")
|
||||||
client().prepareSearch("idx").setTypes("type")
|
|
||||||
.addAggregation(terms("terms")
|
.addAggregation(terms("terms")
|
||||||
.field(SINGLE_VALUED_FIELD_NAME)
|
.field(SINGLE_VALUED_FIELD_NAME)
|
||||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||||
|
@ -1018,14 +1020,15 @@ public class DoubleTermsTests extends AbstractTermsTests {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedByMultiValuedSubAggregation_WithUknownMetric() throws Exception {
|
public void singleValuedField_OrderedByMultiValuedSubAggregation_WithUknownMetric() throws Exception {
|
||||||
|
for (String index : Arrays.asList("idx", "idx_unmapped")) {
|
||||||
try {
|
try {
|
||||||
|
client().prepareSearch(index).setTypes("type")
|
||||||
client().prepareSearch("idx").setTypes("type")
|
|
||||||
.addAggregation(terms("terms")
|
.addAggregation(terms("terms")
|
||||||
.field(SINGLE_VALUED_FIELD_NAME)
|
.field(SINGLE_VALUED_FIELD_NAME + "2")
|
||||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||||
.order(Terms.Order.aggregation("stats.foo", true))
|
.order(Terms.Order.aggregation("stats.foo", true))
|
||||||
.subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
|
.subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))
|
||||||
|
@ -1038,12 +1041,13 @@ public class DoubleTermsTests extends AbstractTermsTests {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedByMultiValuedSubAggregation_WithoutMetric() throws Exception {
|
public void singleValuedField_OrderedByMultiValuedSubAggregation_WithoutMetric() throws Exception {
|
||||||
|
for (String index : Arrays.asList("idx", "idx_unmapped")) {
|
||||||
try {
|
try {
|
||||||
|
client().prepareSearch(index).setTypes("type")
|
||||||
client().prepareSearch("idx").setTypes("type")
|
|
||||||
.addAggregation(terms("terms")
|
.addAggregation(terms("terms")
|
||||||
.field(SINGLE_VALUED_FIELD_NAME)
|
.field(SINGLE_VALUED_FIELD_NAME)
|
||||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||||
|
@ -1058,6 +1062,7 @@ public class DoubleTermsTests extends AbstractTermsTests {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedBySingleValueSubAggregationDesc() throws Exception {
|
public void singleValuedField_OrderedBySingleValueSubAggregationDesc() throws Exception {
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -981,9 +982,9 @@ public class LongTermsTests extends AbstractTermsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedByMissingSubAggregation() throws Exception {
|
public void singleValuedField_OrderedByMissingSubAggregation() throws Exception {
|
||||||
|
for (String index : Arrays.asList("idx", "idx_unmapped")) {
|
||||||
try {
|
try {
|
||||||
|
client().prepareSearch(index).setTypes("type")
|
||||||
client().prepareSearch("idx").setTypes("type")
|
|
||||||
.addAggregation(terms("terms")
|
.addAggregation(terms("terms")
|
||||||
.field(SINGLE_VALUED_FIELD_NAME)
|
.field(SINGLE_VALUED_FIELD_NAME)
|
||||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||||
|
@ -996,12 +997,13 @@ public class LongTermsTests extends AbstractTermsTests {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedByNonMetricsOrMultiBucketSubAggregation() throws Exception {
|
public void singleValuedField_OrderedByNonMetricsOrMultiBucketSubAggregation() throws Exception {
|
||||||
|
for (String index : Arrays.asList("idx", "idx_unmapped")) {
|
||||||
try {
|
try {
|
||||||
|
client().prepareSearch(index).setTypes("type")
|
||||||
client().prepareSearch("idx").setTypes("type")
|
|
||||||
.addAggregation(terms("terms")
|
.addAggregation(terms("terms")
|
||||||
.field(SINGLE_VALUED_FIELD_NAME)
|
.field(SINGLE_VALUED_FIELD_NAME)
|
||||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||||
|
@ -1016,12 +1018,13 @@ public class LongTermsTests extends AbstractTermsTests {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedByMultiValuedSubAggregation_WithUknownMetric() throws Exception {
|
public void singleValuedField_OrderedByMultiValuedSubAggregation_WithUknownMetric() throws Exception {
|
||||||
|
for (String index : Arrays.asList("idx", "idx_unmapped")) {
|
||||||
try {
|
try {
|
||||||
|
client().prepareSearch(index).setTypes("type")
|
||||||
client().prepareSearch("idx").setTypes("type")
|
|
||||||
.addAggregation(terms("terms")
|
.addAggregation(terms("terms")
|
||||||
.field(SINGLE_VALUED_FIELD_NAME)
|
.field(SINGLE_VALUED_FIELD_NAME)
|
||||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||||
|
@ -1036,12 +1039,13 @@ public class LongTermsTests extends AbstractTermsTests {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedByMultiValuedSubAggregation_WithoutMetric() throws Exception {
|
public void singleValuedField_OrderedByMultiValuedSubAggregation_WithoutMetric() throws Exception {
|
||||||
|
for (String index : Arrays.asList("idx", "idx_unmapped")) {
|
||||||
try {
|
try {
|
||||||
|
client().prepareSearch(index).setTypes("type")
|
||||||
client().prepareSearch("idx").setTypes("type")
|
|
||||||
.addAggregation(terms("terms")
|
.addAggregation(terms("terms")
|
||||||
.field(SINGLE_VALUED_FIELD_NAME)
|
.field(SINGLE_VALUED_FIELD_NAME)
|
||||||
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
.collectMode(randomFrom(SubAggCollectionMode.values()))
|
||||||
|
@ -1056,6 +1060,7 @@ public class LongTermsTests extends AbstractTermsTests {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedBySingleValueSubAggregationDesc() throws Exception {
|
public void singleValuedField_OrderedBySingleValueSubAggregationDesc() throws Exception {
|
||||||
|
|
|
@ -44,6 +44,7 @@ import org.junit.Test;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -1363,9 +1364,9 @@ public class StringTermsTests extends AbstractTermsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedByMissingSubAggregation() throws Exception {
|
public void singleValuedField_OrderedByMissingSubAggregation() throws Exception {
|
||||||
|
for (String index : Arrays.asList("idx", "idx_unmapped")) {
|
||||||
try {
|
try {
|
||||||
|
client().prepareSearch(index).setTypes("type")
|
||||||
client().prepareSearch("idx").setTypes("type")
|
|
||||||
.addAggregation(terms("terms")
|
.addAggregation(terms("terms")
|
||||||
.executionHint(randomExecutionHint())
|
.executionHint(randomExecutionHint())
|
||||||
.field(SINGLE_VALUED_FIELD_NAME)
|
.field(SINGLE_VALUED_FIELD_NAME)
|
||||||
|
@ -1379,12 +1380,13 @@ public class StringTermsTests extends AbstractTermsTests {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedByNonMetricsOrMultiBucketSubAggregation() throws Exception {
|
public void singleValuedField_OrderedByNonMetricsOrMultiBucketSubAggregation() throws Exception {
|
||||||
|
for (String index : Arrays.asList("idx", "idx_unmapped")) {
|
||||||
try {
|
try {
|
||||||
|
client().prepareSearch(index).setTypes("type")
|
||||||
client().prepareSearch("idx").setTypes("type")
|
|
||||||
.addAggregation(terms("terms")
|
.addAggregation(terms("terms")
|
||||||
.executionHint(randomExecutionHint())
|
.executionHint(randomExecutionHint())
|
||||||
.field(SINGLE_VALUED_FIELD_NAME)
|
.field(SINGLE_VALUED_FIELD_NAME)
|
||||||
|
@ -1400,11 +1402,13 @@ public class StringTermsTests extends AbstractTermsTests {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedByMultiValuedSubAggregation_WithUknownMetric() throws Exception {
|
public void singleValuedField_OrderedByMultiValuedSubAggregation_WithUknownMetric() throws Exception {
|
||||||
|
for (String index : Arrays.asList("idx", "idx_unmapped")) {
|
||||||
try {
|
try {
|
||||||
SearchResponse response = client().prepareSearch("idx").setTypes("type")
|
SearchResponse response = client().prepareSearch(index).setTypes("type")
|
||||||
.addAggregation(terms("terms")
|
.addAggregation(terms("terms")
|
||||||
.executionHint(randomExecutionHint())
|
.executionHint(randomExecutionHint())
|
||||||
.field(SINGLE_VALUED_FIELD_NAME)
|
.field(SINGLE_VALUED_FIELD_NAME)
|
||||||
|
@ -1419,12 +1423,13 @@ public class StringTermsTests extends AbstractTermsTests {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedByMultiValuedSubAggregation_WithoutMetric() throws Exception {
|
public void singleValuedField_OrderedByMultiValuedSubAggregation_WithoutMetric() throws Exception {
|
||||||
|
for (String index : Arrays.asList("idx", "idx_unmapped")) {
|
||||||
try {
|
try {
|
||||||
|
client().prepareSearch(index).setTypes("type")
|
||||||
client().prepareSearch("idx").setTypes("type")
|
|
||||||
.addAggregation(terms("terms")
|
.addAggregation(terms("terms")
|
||||||
.executionHint(randomExecutionHint())
|
.executionHint(randomExecutionHint())
|
||||||
.field(SINGLE_VALUED_FIELD_NAME)
|
.field(SINGLE_VALUED_FIELD_NAME)
|
||||||
|
@ -1440,6 +1445,7 @@ public class StringTermsTests extends AbstractTermsTests {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleValuedField_OrderedBySingleValueSubAggregationDesc() throws Exception {
|
public void singleValuedField_OrderedBySingleValueSubAggregationDesc() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue