|
@ -7,9 +7,13 @@ import org.apache.solr.client.solrj.response.Group;
|
|
|
import org.elasticsearch.action.search.SearchRequestBuilder;
|
|
|
import org.elasticsearch.action.search.SearchResponse;
|
|
|
import org.elasticsearch.client.transport.TransportClient;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.elasticsearch.search.aggregations.Aggregation;
|
|
|
import org.elasticsearch.search.aggregations.AggregationBuilder;
|
|
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
|
|
import org.elasticsearch.search.aggregations.bucket.filter.Filter;
|
|
|
import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder;
|
|
@ -59,18 +63,25 @@ public class EsAggsTest {
|
|
|
public void termsCardinalityTest() {
|
|
|
TransportClient transportClient = elasticSearchPool.getClient();
|
|
|
|
|
|
QueryBuilder queryBuilder = QueryBuilders.termQuery("patient_id", "848738");
|
|
|
FilterAggregationBuilder filterAgg = AggregationBuilders.filter("patientFilter").filter(queryBuilder);
|
|
|
|
|
|
TermsBuilder termsBuilder = AggregationBuilders.terms("datasetTerms").field("dataset").size(200);
|
|
|
|
|
|
CardinalityBuilder cardinalityBuilder = AggregationBuilders.cardinality("distinctCount")
|
|
|
.field("event_no").precisionThreshold(40000);
|
|
|
|
|
|
termsBuilder.subAggregation(cardinalityBuilder);
|
|
|
filterAgg.subAggregation(termsBuilder);
|
|
|
|
|
|
SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch("json_archives_qc")
|
|
|
.setTypes("qc_metadata_info")
|
|
|
.setSize(0)
|
|
|
.addAggregation(termsBuilder);
|
|
|
|
|
|
.addAggregation(filterAgg);
|
|
|
SearchResponse searchResponse = searchRequestBuilder.get();
|
|
|
StringTerms terms = searchResponse.getAggregations().get("datasetTerms");
|
|
|
|
|
|
Filter filter = searchResponse.getAggregations().get("patientFilter");
|
|
|
StringTerms terms = filter.getAggregations().get("datasetTerms");
|
|
|
for (Terms.Bucket bucket : terms.getBuckets()) {
|
|
|
String key = bucket.getKeyAsString();
|
|
|
Cardinality cardinality = bucket.getAggregations().get("distinctCount");
|