use of com.carrotsearch.hppc.LongHashSet in project elasticsearch by elastic.
the class HistogramIT method testSingleValuedFieldOrderedBySubAggregationAsc.
public void testSingleValuedFieldOrderedBySubAggregationAsc() throws Exception {
SearchResponse response = client().prepareSearch("idx").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);
Histogram histo = response.getAggregations().get("histo");
assertThat(histo, notNullValue());
assertThat(histo.getName(), equalTo("histo"));
assertThat(histo.getBuckets().size(), equalTo(numValueBuckets));
LongHashSet visited = new LongHashSet();
double previousSum = Double.NEGATIVE_INFINITY;
// TODO: use diamond once JI-9019884 is fixed
List<Histogram.Bucket> buckets = new ArrayList<>(histo.getBuckets());
for (int i = 0; i < numValueBuckets; ++i) {
Histogram.Bucket bucket = buckets.get(i);
assertThat(bucket, notNullValue());
long key = ((Number) bucket.getKey()).longValue();
assertTrue(visited.add(key));
int b = (int) (key / interval);
assertThat(bucket.getDocCount(), equalTo(valueCounts[b]));
assertThat(bucket.getAggregations().asList().isEmpty(), is(false));
Sum sum = bucket.getAggregations().get("sum");
assertThat(sum, notNullValue());
long s = 0;
for (int j = 0; j < numDocs; ++j) {
if ((j + 1) / interval == b) {
s += j + 1;
}
}
assertThat(sum.getValue(), equalTo((double) s));
assertThat(sum.getValue(), greaterThanOrEqualTo(previousSum));
previousSum = s;
}
}
use of com.carrotsearch.hppc.LongHashSet in project elasticsearch by elastic.
the class HistogramIT method testSingleValuedFieldOrderedByMultiValuedSubAggregationDesc.
public void testSingleValuedFieldOrderedByMultiValuedSubAggregationDesc() throws Exception {
SearchResponse response = client().prepareSearch("idx").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);
Histogram histo = response.getAggregations().get("histo");
assertThat(histo, notNullValue());
assertThat(histo.getName(), equalTo("histo"));
assertThat(histo.getBuckets().size(), equalTo(numValueBuckets));
LongHashSet visited = new LongHashSet();
double previousSum = Double.POSITIVE_INFINITY;
// TODO: use diamond once JI-9019884 is fixed
List<Histogram.Bucket> buckets = new ArrayList<>(histo.getBuckets());
for (int i = 0; i < numValueBuckets; ++i) {
Histogram.Bucket bucket = buckets.get(i);
assertThat(bucket, notNullValue());
long key = ((Number) bucket.getKey()).longValue();
assertTrue(visited.add(key));
int b = (int) (key / interval);
assertThat(bucket.getDocCount(), equalTo(valueCounts[b]));
assertThat(bucket.getAggregations().asList().isEmpty(), is(false));
Stats stats = bucket.getAggregations().get("stats");
assertThat(stats, notNullValue());
long s = 0;
for (int j = 0; j < numDocs; ++j) {
if ((j + 1) / interval == b) {
s += j + 1;
}
}
assertThat(stats.getSum(), equalTo((double) s));
assertThat(stats.getSum(), lessThanOrEqualTo(previousSum));
previousSum = s;
}
}
use of com.carrotsearch.hppc.LongHashSet in project elasticsearch by elastic.
the class HistogramIT method testSingleValuedFieldOrderedByCountAsc.
public void testSingleValuedFieldOrderedByCountAsc() throws Exception {
SearchResponse response = client().prepareSearch("idx").addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.COUNT_ASC)).execute().actionGet();
assertSearchResponse(response);
Histogram histo = response.getAggregations().get("histo");
assertThat(histo, notNullValue());
assertThat(histo.getName(), equalTo("histo"));
assertThat(histo.getBuckets().size(), equalTo(numValueBuckets));
LongHashSet buckets = new LongHashSet();
// TODO: use diamond once JI-9019884 is fixed
List<Histogram.Bucket> histoBuckets = new ArrayList<>(histo.getBuckets());
long previousCount = Long.MIN_VALUE;
for (int i = 0; i < numValueBuckets; ++i) {
Histogram.Bucket bucket = histoBuckets.get(i);
assertThat(bucket, notNullValue());
long key = ((Number) bucket.getKey()).longValue();
assertEquals(0, key % interval);
assertTrue(buckets.add(key));
assertThat(bucket.getDocCount(), equalTo(valueCounts[(int) (key / interval)]));
assertThat(bucket.getDocCount(), greaterThanOrEqualTo(previousCount));
previousCount = bucket.getDocCount();
}
}
use of com.carrotsearch.hppc.LongHashSet in project elasticsearch by elastic.
the class HistogramIT method testSingleValuedFieldOrderedBySubAggregationDescDeepOrderPath.
public void testSingleValuedFieldOrderedBySubAggregationDescDeepOrderPath() throws Exception {
boolean asc = randomBoolean();
SearchResponse response = client().prepareSearch("idx").addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.aggregation("filter>max", asc)).subAggregation(filter("filter", matchAllQuery()).subAggregation(max("max").field(SINGLE_VALUED_FIELD_NAME)))).execute().actionGet();
assertSearchResponse(response);
Histogram histo = response.getAggregations().get("histo");
assertThat(histo, notNullValue());
assertThat(histo.getName(), equalTo("histo"));
assertThat(histo.getBuckets().size(), equalTo(numValueBuckets));
LongHashSet visited = new LongHashSet();
double prevMax = asc ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
// TODO: use diamond once JI-9019884 is fixed
List<Histogram.Bucket> buckets = new ArrayList<>(histo.getBuckets());
for (int i = 0; i < numValueBuckets; ++i) {
Histogram.Bucket bucket = buckets.get(i);
assertThat(bucket, notNullValue());
long key = ((Number) bucket.getKey()).longValue();
assertTrue(visited.add(key));
int b = (int) (key / interval);
assertThat(bucket.getDocCount(), equalTo(valueCounts[b]));
assertThat(bucket.getAggregations().asList().isEmpty(), is(false));
Filter filter = bucket.getAggregations().get("filter");
assertThat(filter, notNullValue());
assertThat(bucket.getDocCount(), equalTo(filter.getDocCount()));
Max max = filter.getAggregations().get("max");
assertThat(max, Matchers.notNullValue());
assertThat(max.getValue(), asc ? greaterThanOrEqualTo(prevMax) : lessThanOrEqualTo(prevMax));
prevMax = max.getValue();
}
}
use of com.carrotsearch.hppc.LongHashSet in project elasticsearch by elastic.
the class MinDocCountIT method setupSuiteScopeCluster.
@Override
public void setupSuiteScopeCluster() throws Exception {
assertAcked(client().admin().indices().prepareCreate("idx").addMapping("type", "s", "type=keyword").get());
cardinality = randomIntBetween(8, 30);
final List<IndexRequestBuilder> indexRequests = new ArrayList<>();
final Set<String> stringTerms = new HashSet<>();
final LongSet longTerms = new LongHashSet();
for (int i = 0; i < cardinality; ++i) {
String stringTerm;
do {
stringTerm = RandomStrings.randomAsciiOfLength(random(), 8);
} while (!stringTerms.add(stringTerm));
long longTerm;
do {
longTerm = randomInt(cardinality * 2);
} while (!longTerms.add(longTerm));
double doubleTerm = longTerm * Math.PI;
String dateTerm = DateTimeFormat.forPattern("yyyy-MM-dd").print(new DateTime(2014, 1, ((int) longTerm % 20) + 1, 0, 0, DateTimeZone.UTC));
final int frequency = randomBoolean() ? 1 : randomIntBetween(2, 20);
for (int j = 0; j < frequency; ++j) {
indexRequests.add(client().prepareIndex("idx", "type").setSource(jsonBuilder().startObject().field("s", stringTerm).field("l", longTerm).field("d", doubleTerm).field("date", dateTerm).field("match", randomBoolean()).endObject()));
}
}
cardinality = stringTerms.size();
indexRandom(true, indexRequests);
ensureSearchable();
}
Aggregations