Search in sources :

Example 16 with LongHashSet

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;
    }
}
Also used : LongHashSet(com.carrotsearch.hppc.LongHashSet) Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) Bucket(org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket) Bucket(org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket) ArrayList(java.util.ArrayList) Sum(org.elasticsearch.search.aggregations.metrics.sum.Sum) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 17 with LongHashSet

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;
    }
}
Also used : LongHashSet(com.carrotsearch.hppc.LongHashSet) Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) Bucket(org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket) Bucket(org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket) ArrayList(java.util.ArrayList) Stats(org.elasticsearch.search.aggregations.metrics.stats.Stats) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 18 with LongHashSet

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();
    }
}
Also used : LongHashSet(com.carrotsearch.hppc.LongHashSet) Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) Bucket(org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket) Bucket(org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket) ArrayList(java.util.ArrayList) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 19 with LongHashSet

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();
    }
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) Bucket(org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket) Max(org.elasticsearch.search.aggregations.metrics.max.Max) ArrayList(java.util.ArrayList) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse) LongHashSet(com.carrotsearch.hppc.LongHashSet) Bucket(org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket) Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter)

Example 20 with LongHashSet

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();
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) LongHashSet(com.carrotsearch.hppc.LongHashSet) LongSet(com.carrotsearch.hppc.LongSet) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet) LongHashSet(com.carrotsearch.hppc.LongHashSet)

Aggregations

LongHashSet (com.carrotsearch.hppc.LongHashSet)25 LongSet (com.carrotsearch.hppc.LongSet)15 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)7 SearchResponse (org.elasticsearch.action.search.SearchResponse)5 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)5 Bucket (org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket)5 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)5 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)4 ExecutorService (java.util.concurrent.ExecutorService)4 Future (java.util.concurrent.Future)4 HashSet (java.util.HashSet)3 ExecutionException (java.util.concurrent.ExecutionException)3 BytesRef (org.apache.lucene.util.BytesRef)3 LongArrayList (com.carrotsearch.hppc.LongArrayList)2 ConsistentKeyIDAuthority (com.thinkaurelius.titan.diskstorage.idmanagement.ConsistentKeyIDAuthority)2 IDBlockSizer (com.thinkaurelius.titan.graphdb.database.idassigner.IDBlockSizer)2 Callable (java.util.concurrent.Callable)2 Direction (org.apache.tinkerpop.gremlin.structure.Direction)2 Sum (org.elasticsearch.search.aggregations.metrics.sum.Sum)2