Search in sources :

Example 1 with Histogram

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());
}
Also used : Histogram(com.ibm.watson.developer_cloud.discovery.v1.model.Histogram) QueryResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse) QueryOptions(com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Aggregations

WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 Histogram (com.ibm.watson.developer_cloud.discovery.v1.model.Histogram)1 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)1 QueryResponse (com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse)1 Test (org.junit.Test)1