Search in sources :

Example 1 with Min

use of org.elasticsearch.search.aggregations.metrics.min.Min in project elasticsearch by elastic.

the class MinIT method testScriptSingleValued.

@Override
public void testScriptSingleValued() throws Exception {
    Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value", emptyMap());
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(min("min").script(script)).get();
    assertHitCount(searchResponse, 10);
    Min min = searchResponse.getAggregations().get("min");
    assertThat(min, notNullValue());
    assertThat(min.getName(), equalTo("min"));
    assertThat(min.getValue(), equalTo(1.0));
}
Also used : Script(org.elasticsearch.script.Script) Min(org.elasticsearch.search.aggregations.metrics.min.Min) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 2 with Min

use of org.elasticsearch.search.aggregations.metrics.min.Min in project elasticsearch by elastic.

the class MinIT method testSingleValuedField.

@Override
public void testSingleValuedField() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(min("min").field("value")).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Min min = searchResponse.getAggregations().get("min");
    assertThat(min, notNullValue());
    assertThat(min.getName(), equalTo("min"));
    assertThat(min.getValue(), equalTo(1.0));
}
Also used : Min(org.elasticsearch.search.aggregations.metrics.min.Min) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 3 with Min

use of org.elasticsearch.search.aggregations.metrics.min.Min in project elasticsearch by elastic.

the class MinIT method testScriptMultiValued.

@Override
public void testScriptMultiValued() throws Exception {
    Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['values'].values", emptyMap());
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(min("min").script(script)).get();
    assertHitCount(searchResponse, 10);
    Min min = searchResponse.getAggregations().get("min");
    assertThat(min, notNullValue());
    assertThat(min.getName(), equalTo("min"));
    assertThat(min.getValue(), equalTo(2.0));
}
Also used : Script(org.elasticsearch.script.Script) Min(org.elasticsearch.search.aggregations.metrics.min.Min) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 4 with Min

use of org.elasticsearch.search.aggregations.metrics.min.Min in project elasticsearch by elastic.

the class MinIT method testMultiValuedField.

@Override
public void testMultiValuedField() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(min("min").field("values")).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Min min = searchResponse.getAggregations().get("min");
    assertThat(min, notNullValue());
    assertThat(min.getName(), equalTo("min"));
    assertThat(min.getValue(), equalTo(2.0));
}
Also used : Min(org.elasticsearch.search.aggregations.metrics.min.Min) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 5 with Min

use of org.elasticsearch.search.aggregations.metrics.min.Min in project elasticsearch by elastic.

the class MinIT method testSingleValuedFieldWithValueScript.

@Override
public void testSingleValuedFieldWithValueScript() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(min("min").field("value").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap()))).get();
    assertHitCount(searchResponse, 10);
    Min min = searchResponse.getAggregations().get("min");
    assertThat(min, notNullValue());
    assertThat(min.getName(), equalTo("min"));
    assertThat(min.getValue(), equalTo(0.0));
}
Also used : Script(org.elasticsearch.script.Script) Min(org.elasticsearch.search.aggregations.metrics.min.Min) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

Min (org.elasticsearch.search.aggregations.metrics.min.Min)20 SearchResponse (org.elasticsearch.action.search.SearchResponse)18 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)17 Script (org.elasticsearch.script.Script)8 HashMap (java.util.HashMap)4 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)2 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)2 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 Document (org.apache.lucene.document.Document)1 Field (org.apache.lucene.document.Field)1 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)1 IndexReader (org.apache.lucene.index.IndexReader)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)1 Term (org.apache.lucene.index.Term)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1