use of org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrix in project elasticsearch by elastic.
the class AdjacencyMatrixIT method testSimple.
public void testSimple() throws Exception {
SearchResponse response = client().prepareSearch("idx").addAggregation(adjacencyMatrix("tags", newMap("tag1", termQuery("tag", "tag1")).add("tag2", termQuery("tag", "tag2")))).execute().actionGet();
assertSearchResponse(response);
AdjacencyMatrix matrix = response.getAggregations().get("tags");
assertThat(matrix, notNullValue());
assertThat(matrix.getName(), equalTo("tags"));
int expected = numMultiTagDocs > 0 ? 3 : 2;
assertThat(matrix.getBuckets().size(), equalTo(expected));
AdjacencyMatrix.Bucket bucket = matrix.getBucketByKey("tag1");
assertThat(bucket, Matchers.notNullValue());
assertThat(bucket.getDocCount(), equalTo((long) numTag1Docs));
bucket = matrix.getBucketByKey("tag2");
assertThat(bucket, Matchers.notNullValue());
assertThat(bucket.getDocCount(), equalTo((long) numTag2Docs));
bucket = matrix.getBucketByKey("tag1&tag2");
if (numMultiTagDocs == 0) {
assertThat(bucket, Matchers.nullValue());
} else {
assertThat(bucket, Matchers.notNullValue());
assertThat(bucket.getDocCount(), equalTo((long) numMultiTagDocs));
}
}
Aggregations