use of org.eclipse.kapua.service.datastore.internal.elasticsearch.MetricInfoBuilder in project kapua by eclipse.
the class EsMetricDAO method query.
public MetricInfoListResult query(MetricInfoQuery query) throws Exception {
// get one plus (if there is one) to later get the next key value
MetricInfoQueryImpl localQuery = new MetricInfoQueryImpl();
localQuery.copy(query);
localQuery.setLimit(query.getLimit() + 1);
MetricInfoQueryConverter mic = new MetricInfoQueryConverter();
SearchRequestBuilder builder = mic.toSearchRequestBuilder(esTypeDAO.getIndexName(), esTypeDAO.getTypeName(), localQuery);
SearchResponse response = builder.get(TimeValue.timeValueMillis(EsUtils.getQueryTimeout()));
SearchHits searchHits = response.getHits();
if (searchHits == null || searchHits.getTotalHits() == 0)
return new MetricInfoListResultImpl();
int i = 0;
int searchHitsSize = searchHits.getHits().length;
List<MetricInfo> metricInfos = new ArrayList<MetricInfo>();
MetricInfoBuilder metricInfoBuilder = new MetricInfoBuilder();
for (SearchHit searchHit : searchHits.getHits()) {
if (i < query.getLimit()) {
MetricInfo metricInfo = metricInfoBuilder.build(searchHit).getKapuaMetricInfo();
metricInfos.add(metricInfo);
}
i++;
}
// TODO check equivalence with CX with Pierantonio
// TODO what is this nextKey
Object nextKey = null;
if (searchHitsSize > query.getLimit()) {
nextKey = query.getLimit();
}
MetricInfoListResult result = new MetricInfoListResultImpl(nextKey, metricInfos.size());
result.addAll(metricInfos);
return result;
}
Aggregations