use of com.ibm.watson.developer_cloud.discovery.v1.model.Histogram in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method queryWithAggregationHistogramIsSuccessful.
@Test
public void queryWithAggregationHistogramIsSuccessful() throws InterruptedException {
String collectionId = setupTestDocuments();
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
StringBuilder sb = new StringBuilder();
sb.append(AggregationType.HISTOGRAM);
sb.append(Operator.OPENING_GROUPING);
sb.append("field");
sb.append(Operator.AND);
sb.append(5L);
sb.append(Operator.CLOSING_GROUPING);
String aggregation = sb.toString();
queryBuilder.aggregation(aggregation);
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
Histogram histogram = (Histogram) queryResponse.getAggregations().get(0);
Long interval = histogram.getInterval();
assertEquals(new Long(5), interval);
assertEquals(2, histogram.getResults().size());
}
Aggregations