Adressing comments
This commit is contained in:
parent
b01e3f0d3b
commit
cbcbe75cf0
|
@ -57,7 +57,7 @@ public class FiltersAggregator extends BucketsAggregator {
|
||||||
public static final ParseField OTHER_BUCKET_FIELD = new ParseField("other_bucket");
|
public static final ParseField OTHER_BUCKET_FIELD = new ParseField("other_bucket");
|
||||||
public static final ParseField OTHER_BUCKET_KEY_FIELD = new ParseField("other_bucket_key");
|
public static final ParseField OTHER_BUCKET_KEY_FIELD = new ParseField("other_bucket_key");
|
||||||
|
|
||||||
public static class KeyedFilter implements Writeable<KeyedFilter>, ToXContent, Comparable<KeyedFilter> {
|
public static class KeyedFilter implements Writeable<KeyedFilter>, ToXContent {
|
||||||
|
|
||||||
static final KeyedFilter PROTOTYPE = new KeyedFilter("", EmptyQueryBuilder.PROTOTYPE);
|
static final KeyedFilter PROTOTYPE = new KeyedFilter("", EmptyQueryBuilder.PROTOTYPE);
|
||||||
private final String key;
|
private final String key;
|
||||||
|
@ -122,11 +122,6 @@ public class FiltersAggregator extends BucketsAggregator {
|
||||||
return Objects.equals(key, other.key)
|
return Objects.equals(key, other.key)
|
||||||
&& Objects.equals(filter, other.filter);
|
&& Objects.equals(filter, other.filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(KeyedFilter o) {
|
|
||||||
return this.key.compareTo(o.key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String[] keys;
|
private final String[] keys;
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder<FiltersAggregato
|
||||||
private FiltersAggregatorBuilder(String name, List<KeyedFilter> filters) {
|
private FiltersAggregatorBuilder(String name, List<KeyedFilter> filters) {
|
||||||
super(name, InternalFilters.TYPE);
|
super(name, InternalFilters.TYPE);
|
||||||
// internally we want to have a fixed order of filters, regardless of the order of the filters in the request
|
// internally we want to have a fixed order of filters, regardless of the order of the filters in the request
|
||||||
Collections.sort(filters);
|
Collections.sort(filters, (KeyedFilter kf1, KeyedFilter kf2) -> kf1.key().compareTo(kf2.key()));
|
||||||
this.filters = filters;
|
this.filters = filters;
|
||||||
this.keyed = true;
|
this.keyed = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,9 @@ import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -488,13 +490,9 @@ public class FiltersIT extends ESIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static KeyedFilter[] randomOrder(KeyedFilter... filters) {
|
private static KeyedFilter[] randomOrder(KeyedFilter... filters) {
|
||||||
for (int i = 0; i < filters.length; i++) {
|
List<KeyedFilter> asList = Arrays.asList(filters);
|
||||||
KeyedFilter tmp = filters[i];
|
Collections.shuffle(asList);
|
||||||
int index = randomInt(filters.length - 1);
|
return asList.toArray(new KeyedFilter[filters.length]);
|
||||||
filters[i] = filters[index];
|
|
||||||
filters[index] = tmp;
|
|
||||||
}
|
|
||||||
return filters;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue