Simple aggregation using java API - elastic 1.x


(Mmaia) #1

I am new to aggregations with Elastic Search and have been stuck for a couple of hours with this very simple example taken from this link: https://www.elastic.co/guide/en/elasticsearch/guide/1.x/_aggregation_test_drive.html

Basically I am trying to do the java api version of this very simple working aggregation:

http://localhost:9200/cars/transactions/_search?search_type=count
{
 "aggs" : {
   "colors" : {
       "terms" : {
           "field" : "color"
       }
    }
  }
}

and this is the java version I am trying to build but it returns empty buckets:

SearchResponse sr = client
        .prepareSearch("cars")
        .setTypes("transactions")
        .setSearchType(SearchType.COUNT)
        .addAggregation(AggregationBuilders.terms("colors").field("color"))
        .execute()
        .actionGet();

while using the elastic DSL I get a proper resopnse with buckets grouped by colors but with the java version I get an empty bucket.


(Mmaia) #2

Hi,

java code is working, my issue was related to using this code in unit testing and for some reason had bad results, when used against a running elastic cluster the code works fine.
I've tried to delete the question but couldn't find the option.


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.