use of org.elasticsearch.search.aggregations.metrics.max.Max in project elasticsearch by elastic.
the class TopHitsIT method testSortByBucket.
public void testSortByBucket() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").executionHint(randomExecutionHint()).field(TERMS_AGGS_FIELD).order(Terms.Order.aggregation("max_sort", false)).subAggregation(topHits("hits").sort(SortBuilders.fieldSort(SORT_FIELD).order(SortOrder.DESC)).trackScores(true)).subAggregation(max("max_sort").field(SORT_FIELD))).get();
assertSearchResponse(response);
Terms terms = response.getAggregations().get("terms");
assertThat(terms, notNullValue());
assertThat(terms.getName(), equalTo("terms"));
assertThat(terms.getBuckets().size(), equalTo(5));
long higestSortValue = 50;
int currentBucket = 4;
for (Terms.Bucket bucket : terms.getBuckets()) {
assertThat(key(bucket), equalTo("val" + currentBucket--));
assertThat(bucket.getDocCount(), equalTo(10L));
TopHits topHits = bucket.getAggregations().get("hits");
SearchHits hits = topHits.getHits();
assertThat(hits.getTotalHits(), equalTo(10L));
assertThat(hits.getHits().length, equalTo(3));
assertThat((Long) hits.getAt(0).getSortValues()[0], equalTo(higestSortValue));
assertThat((Long) hits.getAt(1).getSortValues()[0], equalTo(higestSortValue - 1));
assertThat((Long) hits.getAt(2).getSortValues()[0], equalTo(higestSortValue - 2));
Max max = bucket.getAggregations().get("max_sort");
assertThat(max.getValue(), equalTo(((Long) higestSortValue).doubleValue()));
higestSortValue -= 10;
}
}
use of org.elasticsearch.search.aggregations.metrics.max.Max in project elasticsearch by elastic.
the class MaxIT method testScriptMultiValued.
@Override
public void testScriptMultiValued() throws Exception {
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(max("max").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['values'].values", Collections.emptyMap()))).get();
assertHitCount(searchResponse, 10);
Max max = searchResponse.getAggregations().get("max");
assertThat(max, notNullValue());
assertThat(max.getName(), equalTo("max"));
assertThat(max.getValue(), equalTo(12.0));
}
use of org.elasticsearch.search.aggregations.metrics.max.Max in project elasticsearch by elastic.
the class MaxIT method testScriptSingleValuedWithParams.
@Override
public void testScriptSingleValuedWithParams() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("inc", 1);
Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value + inc", params);
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(max("max").script(script)).get();
assertHitCount(searchResponse, 10);
Max max = searchResponse.getAggregations().get("max");
assertThat(max, notNullValue());
assertThat(max.getName(), equalTo("max"));
assertThat(max.getValue(), equalTo(11.0));
}
use of org.elasticsearch.search.aggregations.metrics.max.Max in project elasticsearch by elastic.
the class MaxIT method testSingleValuedFieldPartiallyUnmapped.
@Override
public void testSingleValuedFieldPartiallyUnmapped() throws Exception {
SearchResponse searchResponse = client().prepareSearch("idx", "idx_unmapped").setQuery(matchAllQuery()).addAggregation(max("max").field("value")).execute().actionGet();
assertHitCount(searchResponse, 10);
Max max = searchResponse.getAggregations().get("max");
assertThat(max, notNullValue());
assertThat(max.getName(), equalTo("max"));
assertThat(max.getValue(), equalTo(10.0));
}
use of org.elasticsearch.search.aggregations.metrics.max.Max in project elasticsearch by elastic.
the class MaxIT method testUnmapped.
@Override
public void testUnmapped() throws Exception {
SearchResponse searchResponse = client().prepareSearch("idx_unmapped").setQuery(matchAllQuery()).addAggregation(max("max").field("value")).execute().actionGet();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L));
Max max = searchResponse.getAggregations().get("max");
assertThat(max, notNullValue());
assertThat(max.getName(), equalTo("max"));
assertThat(max.getValue(), equalTo(Double.NEGATIVE_INFINITY));
}
Aggregations