use of org.elasticsearch.action.get.MultiGetResponse in project incubator-skywalking by apache.
the class ServiceMetricEsUIDAO method getServiceResponseTimeTrend.
@Override
public List<Integer> getServiceResponseTimeTrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(durationPoints, new ElasticSearchClient.MultiGetRowHandler<DurationPoint>() {
@Override
public void accept(DurationPoint durationPoint) {
String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
add(tableName, ServiceMetricTable.TABLE_TYPE, id);
}
});
List<Integer> trends = new LinkedList<>();
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
long calls = ((Number) response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue();
long durationSum = ((Number) response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)).longValue();
trends.add((int) (durationSum / calls));
} else {
trends.add(0);
}
}
return trends;
}
use of org.elasticsearch.action.get.MultiGetResponse in project incubator-skywalking by apache.
the class ServiceMetricEsUIDAO method getServiceTPSTrend.
@Override
public List<Integer> getServiceTPSTrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(durationPoints, new ElasticSearchClient.MultiGetRowHandler<DurationPoint>() {
@Override
public void accept(DurationPoint durationPoint) {
String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
add(tableName, ServiceMetricTable.TABLE_TYPE, id);
}
});
List<Integer> trends = new LinkedList<>();
MultiGetResponse multiGetResponse = prepareMultiGet.get();
int index = 0;
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
long calls = ((Number) response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue();
long secondBetween = durationPoints.get(index).getSecondsBetween();
trends.add((int) (calls / secondBetween));
} else {
trends.add(0);
}
index++;
}
return trends;
}
use of org.elasticsearch.action.get.MultiGetResponse in project pancm_project by xuwujing.
the class EsHighLevelRestTest2 method multiGet.
/**
* 多查询使用
*
* @throws IOException
*/
private static void multiGet() throws IOException {
MultiGetRequest request = new MultiGetRequest();
request.add(new MultiGetRequest.Item("estest", "estest", "1"));
request.add(new MultiGetRequest.Item("user", "userindex", "2"));
// 禁用源检索,默认启用
// request.add(new MultiGetRequest.Item("user", "userindex", "2").fetchSourceContext(FetchSourceContext.DO_NOT_FETCH_SOURCE));
// 同步构建
MultiGetResponse response = client.mget(request, RequestOptions.DEFAULT);
for (MultiGetItemResponse item : response.getResponses()) {
assertNull(item.getFailure());
GetResponse get = item.getResponse();
String index = item.getIndex();
String type = item.getType();
String id = item.getId();
// 如果请求存在
if (get.isExists()) {
long version = get.getVersion();
String sourceAsString = get.getSourceAsString();
Map<String, Object> sourceAsMap = get.getSourceAsMap();
byte[] sourceAsBytes = get.getSourceAsBytes();
System.out.println("查询的结果:" + sourceAsMap);
} else {
System.out.println("没有找到该文档!");
}
}
}
use of org.elasticsearch.action.get.MultiGetResponse in project yacy_grid_mcp by yacy.
the class ElasticsearchClient method existBulk.
public Set<String> existBulk(String indexName, String typeName, final Collection<String> ids) {
if (ids == null || ids.size() == 0)
return new HashSet<>();
MultiGetResponse multiGetItemResponses = elasticsearchClient.prepareMultiGet().add(indexName, typeName, ids).get();
Set<String> er = new HashSet<>();
for (MultiGetItemResponse itemResponse : multiGetItemResponses) {
GetResponse response = itemResponse.getResponse();
if (response.isExists()) {
er.add(response.getId());
}
}
return er;
}
use of org.elasticsearch.action.get.MultiGetResponse in project jnosql-diana-driver by eclipse.
the class EntityConverter method executeId.
private static void executeId(DocumentQuery query, RestHighLevelClient client, String index, QueryConverterResult select, List<DocumentEntity> entities) throws IOException {
String type = query.getDocumentCollection();
MultiGetRequest multiGetRequest = new MultiGetRequest();
select.getIds().stream().map(id -> new MultiGetRequest.Item(index, type, id)).forEach(multiGetRequest::add);
MultiGetResponse responses = client.multiGet(multiGetRequest);
Stream.of(responses.getResponses()).map(MultiGetItemResponse::getResponse).map(ElasticsearchEntry::of).filter(ElasticsearchEntry::isNotEmpty).map(ElasticsearchEntry::toEntity).forEach(entities::add);
}
Aggregations