use of org.elasticsearch.search.aggregations.bucket.filter.Filter in project elasticsearch by elastic.
the class LongTermsIT method testSingleValuedFieldOrderedBySubAggregationAscMultiHierarchyLevels.
public void testSingleValuedFieldOrderedBySubAggregationAscMultiHierarchyLevels() throws Exception {
boolean asc = randomBoolean();
SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("tags").field("num_tag").collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.aggregation("filter1>filter2>max", asc)).subAggregation(filter("filter1", QueryBuilders.matchAllQuery()).subAggregation(filter("filter2", QueryBuilders.matchAllQuery()).subAggregation(max("max").field(SINGLE_VALUED_FIELD_NAME))))).execute().actionGet();
assertSearchResponse(response);
Terms tags = response.getAggregations().get("tags");
assertThat(tags, notNullValue());
assertThat(tags.getName(), equalTo("tags"));
assertThat(tags.getBuckets().size(), equalTo(2));
Iterator<Terms.Bucket> iters = tags.getBuckets().iterator();
// the max for "1" is 2
// the max for "0" is 4
Terms.Bucket tag = iters.next();
assertThat(tag, notNullValue());
assertThat(key(tag), equalTo(asc ? "1" : "0"));
assertThat(tag.getDocCount(), equalTo(asc ? 3L : 2L));
Filter filter1 = tag.getAggregations().get("filter1");
assertThat(filter1, notNullValue());
assertThat(filter1.getDocCount(), equalTo(asc ? 3L : 2L));
Filter filter2 = filter1.getAggregations().get("filter2");
assertThat(filter2, notNullValue());
assertThat(filter2.getDocCount(), equalTo(asc ? 3L : 2L));
Max max = filter2.getAggregations().get("max");
assertThat(max, notNullValue());
assertThat(max.getValue(), equalTo(asc ? 2.0 : 4.0));
tag = iters.next();
assertThat(tag, notNullValue());
assertThat(key(tag), equalTo(asc ? "0" : "1"));
assertThat(tag.getDocCount(), equalTo(asc ? 2L : 3L));
filter1 = tag.getAggregations().get("filter1");
assertThat(filter1, notNullValue());
assertThat(filter1.getDocCount(), equalTo(asc ? 2L : 3L));
filter2 = filter1.getAggregations().get("filter2");
assertThat(filter2, notNullValue());
assertThat(filter2.getDocCount(), equalTo(asc ? 2L : 3L));
max = filter2.getAggregations().get("max");
assertThat(max, notNullValue());
assertThat(max.getValue(), equalTo(asc ? 4.0 : 2.0));
}
use of org.elasticsearch.search.aggregations.bucket.filter.Filter in project elasticsearch by elastic.
the class ShardReduceIT method testFilter.
public void testFilter() throws Exception {
SearchResponse response = client().prepareSearch("idx").setQuery(QueryBuilders.matchAllQuery()).addAggregation(filter("filter", QueryBuilders.matchAllQuery()).subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0))).execute().actionGet();
assertSearchResponse(response);
Filter filter = response.getAggregations().get("filter");
Histogram histo = filter.getAggregations().get("histo");
assertThat(histo.getBuckets().size(), equalTo(4));
}
use of org.elasticsearch.search.aggregations.bucket.filter.Filter in project elasticsearch by elastic.
the class LongTermsIT method testSingleValuedFieldOrderedBySingleBucketSubAggregationAsc.
public void testSingleValuedFieldOrderedBySingleBucketSubAggregationAsc() throws Exception {
boolean asc = randomBoolean();
SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("num_tags").field("num_tag").collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.aggregation("filter", asc)).subAggregation(filter("filter", QueryBuilders.matchAllQuery()))).get();
assertSearchResponse(response);
Terms tags = response.getAggregations().get("num_tags");
assertThat(tags, notNullValue());
assertThat(tags.getName(), equalTo("num_tags"));
assertThat(tags.getBuckets().size(), equalTo(2));
Iterator<Terms.Bucket> iters = tags.getBuckets().iterator();
Terms.Bucket tag = iters.next();
assertThat(tag, notNullValue());
assertThat(key(tag), equalTo(asc ? "0" : "1"));
assertThat(tag.getDocCount(), equalTo(asc ? 2L : 3L));
Filter filter = tag.getAggregations().get("filter");
assertThat(filter, notNullValue());
assertThat(filter.getDocCount(), equalTo(asc ? 2L : 3L));
tag = iters.next();
assertThat(tag, notNullValue());
assertThat(key(tag), equalTo(asc ? "1" : "0"));
assertThat(tag.getDocCount(), equalTo(asc ? 3L : 2L));
filter = tag.getAggregations().get("filter");
assertThat(filter, notNullValue());
assertThat(filter.getDocCount(), equalTo(asc ? 3L : 2L));
}
use of org.elasticsearch.search.aggregations.bucket.filter.Filter in project elasticsearch by elastic.
the class StringTermsIT method testSingleValuedFieldOrderedBySubAggregationAscMultiHierarchyLevelsSpecialCharsNoDotNotation.
public void testSingleValuedFieldOrderedBySubAggregationAscMultiHierarchyLevelsSpecialCharsNoDotNotation() throws Exception {
StringBuilder filter2NameBuilder = new StringBuilder("filt.er2");
filter2NameBuilder.append(randomAsciiOfLengthBetween(3, 10).replace("[", "").replace("]", "").replace(">", ""));
String filter2Name = filter2NameBuilder.toString();
StringBuilder statsNameBuilder = new StringBuilder("st.ats");
statsNameBuilder.append(randomAsciiOfLengthBetween(3, 10).replace("[", "").replace("]", "").replace(">", ""));
String statsName = statsNameBuilder.toString();
boolean asc = randomBoolean();
SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("tags").executionHint(randomExecutionHint()).field("tag").collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.aggregation("filter1>" + filter2Name + ">" + statsName + "[max]", asc)).subAggregation(filter("filter1", QueryBuilders.matchAllQuery()).subAggregation(filter(filter2Name, QueryBuilders.matchAllQuery()).subAggregation(stats(statsName).field("i"))))).execute().actionGet();
assertSearchResponse(response);
Terms tags = response.getAggregations().get("tags");
assertThat(tags, notNullValue());
assertThat(tags.getName(), equalTo("tags"));
assertThat(tags.getBuckets().size(), equalTo(2));
Iterator<Terms.Bucket> iters = tags.getBuckets().iterator();
// the max for "more" is 2
// the max for "less" is 4
Terms.Bucket tag = iters.next();
assertThat(tag, notNullValue());
assertThat(key(tag), equalTo(asc ? "more" : "less"));
assertThat(tag.getDocCount(), equalTo(asc ? 3L : 2L));
Filter filter1 = tag.getAggregations().get("filter1");
assertThat(filter1, notNullValue());
assertThat(filter1.getDocCount(), equalTo(asc ? 3L : 2L));
Filter filter2 = filter1.getAggregations().get(filter2Name);
assertThat(filter2, notNullValue());
assertThat(filter2.getDocCount(), equalTo(asc ? 3L : 2L));
Stats stats = filter2.getAggregations().get(statsName);
assertThat(stats, notNullValue());
assertThat(stats.getMax(), equalTo(asc ? 2.0 : 4.0));
tag = iters.next();
assertThat(tag, notNullValue());
assertThat(key(tag), equalTo(asc ? "less" : "more"));
assertThat(tag.getDocCount(), equalTo(asc ? 2L : 3L));
filter1 = tag.getAggregations().get("filter1");
assertThat(filter1, notNullValue());
assertThat(filter1.getDocCount(), equalTo(asc ? 2L : 3L));
filter2 = filter1.getAggregations().get(filter2Name);
assertThat(filter2, notNullValue());
assertThat(filter2.getDocCount(), equalTo(asc ? 2L : 3L));
stats = filter2.getAggregations().get(statsName);
assertThat(stats, notNullValue());
assertThat(stats.getMax(), equalTo(asc ? 4.0 : 2.0));
}
use of org.elasticsearch.search.aggregations.bucket.filter.Filter in project elasticsearch by elastic.
the class StringTermsIT method testSingleValuedFieldOrderedBySubAggregationAscMultiHierarchyLevels.
public void testSingleValuedFieldOrderedBySubAggregationAscMultiHierarchyLevels() throws Exception {
boolean asc = randomBoolean();
SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("tags").executionHint(randomExecutionHint()).field("tag").collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.aggregation("filter1>filter2>stats.max", asc)).subAggregation(filter("filter1", QueryBuilders.matchAllQuery()).subAggregation(filter("filter2", QueryBuilders.matchAllQuery()).subAggregation(stats("stats").field("i"))))).execute().actionGet();
assertSearchResponse(response);
Terms tags = response.getAggregations().get("tags");
assertThat(tags, notNullValue());
assertThat(tags.getName(), equalTo("tags"));
assertThat(tags.getBuckets().size(), equalTo(2));
Iterator<Terms.Bucket> iters = tags.getBuckets().iterator();
// the max for "more" is 2
// the max for "less" is 4
Terms.Bucket tag = iters.next();
assertThat(tag, notNullValue());
assertThat(key(tag), equalTo(asc ? "more" : "less"));
assertThat(tag.getDocCount(), equalTo(asc ? 3L : 2L));
Filter filter1 = tag.getAggregations().get("filter1");
assertThat(filter1, notNullValue());
assertThat(filter1.getDocCount(), equalTo(asc ? 3L : 2L));
Filter filter2 = filter1.getAggregations().get("filter2");
assertThat(filter2, notNullValue());
assertThat(filter2.getDocCount(), equalTo(asc ? 3L : 2L));
Stats stats = filter2.getAggregations().get("stats");
assertThat(stats, notNullValue());
assertThat(stats.getMax(), equalTo(asc ? 2.0 : 4.0));
tag = iters.next();
assertThat(tag, notNullValue());
assertThat(key(tag), equalTo(asc ? "less" : "more"));
assertThat(tag.getDocCount(), equalTo(asc ? 2L : 3L));
filter1 = tag.getAggregations().get("filter1");
assertThat(filter1, notNullValue());
assertThat(filter1.getDocCount(), equalTo(asc ? 2L : 3L));
filter2 = filter1.getAggregations().get("filter2");
assertThat(filter2, notNullValue());
assertThat(filter2.getDocCount(), equalTo(asc ? 2L : 3L));
stats = filter2.getAggregations().get("stats");
assertThat(stats, notNullValue());
assertThat(stats.getMax(), equalTo(asc ? 4.0 : 2.0));
}
Aggregations