本文整理汇总了Java中org.elasticsearch.action.get.MultiGetResponse.getResponses方法的典型用法代码示例。如果您正苦于以下问题:Java MultiGetResponse.getResponses方法的具体用法?Java MultiGetResponse.getResponses怎么用?Java MultiGetResponse.getResponses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.get.MultiGetResponse
的用法示例。
在下文中一共展示了MultiGetResponse.getResponses方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findDocuments
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
/**
* Find a set of documents.
*
* @param ids The unique IDs of the documents you wish to find.
* @param index The index in which the document exists in Elasticsearch.
* @param documentType The document type in Elasticsearch for this document.
* @param javaType The concrete java type the document represents.
*/
final protected <T extends IDocument> IPage<T> findDocuments(Set<String> ids, String index, String documentType, Class<T> javaType) {
MultiGetResponse response = this.getClient().prepareMultiGet().add(index, documentType, ids).execute().actionGet();
List<T> results = Lists.newArrayListWithCapacity(ids.size());
for (MultiGetItemResponse item : response.getResponses()) {
if (item.isFailed()) {
throw new SearchServiceException("Unexpected failure while searching for documents.");
}
results.add(this.getDocumentFromSearchResponse(item.getResponse(), javaType));
}
IPage page = Page.of(results);
page.setPageSize(results.size());
page.setPageNumber(1);
page.setTotalElements(results.size());
return page;
}
示例2: getTpsMetric
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
@Override public JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
long timeBucket = startTimeBucket;
do {
String id = timeBucket + Const.ID_SPLIT + instanceId;
prepareMultiGet.add(InstanceMetricTable.TABLE, InstanceMetricTable.TABLE_TYPE, id);
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
}
while (timeBucket <= endTimeBucket);
JsonArray metrics = new JsonArray();
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
metrics.add(((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue());
} else {
metrics.add(0);
}
}
return metrics;
}
示例3: getRespTimeMetric
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
@Override public JsonArray getRespTimeMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
int i = 0;
long timeBucket;
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), startTimeBucket, i);
String id = timeBucket + Const.ID_SPLIT + instanceId;
prepareMultiGet.add(InstanceMetricTable.TABLE, InstanceMetricTable.TABLE_TYPE, id);
i++;
}
while (timeBucket <= endTimeBucket);
JsonArray metrics = new JsonArray();
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
long callTimes = ((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue();
long costTotal = ((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)).longValue();
metrics.add(costTotal / callTimes);
} else {
metrics.add(0);
}
}
return metrics;
}
示例4: getMetric
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
@Override public JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket) {
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
long timeBucket = startTimeBucket;
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
String id = timeBucket + Const.ID_SPLIT + instanceId;
prepareMultiGet.add(CpuMetricTable.TABLE, CpuMetricTable.TABLE_TYPE, id);
}
while (timeBucket <= endTimeBucket);
JsonArray metrics = new JsonArray();
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
double cpuUsed = ((Number)response.getResponse().getSource().get(CpuMetricTable.COLUMN_USAGE_PERCENT)).doubleValue();
metrics.add((int)(cpuUsed * 100));
} else {
metrics.add(0);
}
}
return metrics;
}
示例5: queryForObjects
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
/**
* http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-multi-get.html
* @param clzz
* @param ids
* @return
*/
public <T> List<T> queryForObjects(Class<T> clzz, String... ids) throws SearchException {
String typeName = this.getTypeNameFromClass(clzz);
Timer.Context timer = searchMetrics.indexTimer(typeName, "queryForObjects");
try {
MultiGetRequestBuilder request = client.prepareMultiGet();
request.add(indexName, typeName, ids);
MultiGetResponse response = request.execute().actionGet();
List<T> results = new ArrayList<T>();
for(MultiGetItemResponse resp : response.getResponses()){
if(!resp.isFailed()){
T o = this.docMapper.asObject(clzz, resp.getResponse().getSourceAsString());
results.add(o);
}
}
searchMetrics.indexIncr(typeName, "queryForObjects");
return results;
} catch (Exception e) {
searchMetrics.failedIncr(typeName, "queryForObjects", e);
logger.error("queryForObjects Error. ", e);
throw new SearchException("queryForObjects Error. typeName="+typeName+", ids="+ids, e);
}finally {
timer.stop();
}
}
示例6: testThatSourceFilteringIsSupported
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void testThatSourceFilteringIsSupported() throws Exception {
assertAcked(prepareCreate("test").addAlias(new Alias("alias")));
BytesReference sourceBytesRef = jsonBuilder().startObject()
.array("field", "1", "2")
.startObject("included").field("field", "should be seen").field("hidden_field", "should not be seen").endObject()
.field("excluded", "should not be seen")
.endObject().bytes();
for (int i = 0; i < 100; i++) {
client().prepareIndex("test", "type", Integer.toString(i)).setSource(sourceBytesRef, XContentType.JSON).get();
}
MultiGetRequestBuilder request = client().prepareMultiGet();
for (int i = 0; i < 100; i++) {
if (i % 2 == 0) {
request.add(new MultiGetRequest.Item(indexOrAlias(), "type", Integer.toString(i))
.fetchSourceContext(new FetchSourceContext(true, new String[] {"included"}, new String[] {"*.hidden_field"})));
} else {
request.add(new MultiGetRequest.Item(indexOrAlias(), "type", Integer.toString(i))
.fetchSourceContext(new FetchSourceContext(false)));
}
}
MultiGetResponse response = request.get();
assertThat(response.getResponses().length, equalTo(100));
for (int i = 0; i < 100; i++) {
MultiGetItemResponse responseItem = response.getResponses()[i];
assertThat(responseItem.getIndex(), equalTo("test"));
if (i % 2 == 0) {
Map<String, Object> source = responseItem.getResponse().getSourceAsMap();
assertThat(source.size(), equalTo(1));
assertThat(source, hasKey("included"));
assertThat(((Map<String, Object>) source.get("included")).size(), equalTo(1));
assertThat(((Map<String, Object>) source.get("included")), hasKey("field"));
} else {
assertThat(responseItem.getResponse().getSourceAsBytes(), nullValue());
}
}
}
示例7: mapResults
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
@Override
public <T> LinkedList<T> mapResults(MultiGetResponse responses, Class<T> clazz) {
LinkedList<T> list = new LinkedList<T>();
for (MultiGetItemResponse response : responses.getResponses()) {
if (!response.isFailed() && response.getResponse().isExists()) {
T result = mapEntity(response.getResponse().getSourceAsString(), clazz);
setPersistentEntityId(result, response.getResponse().getId(), clazz);
list.add(result);
}
}
return list;
}
示例8: findAll
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<T> findAll(final List<String> ids) {
if (ids.isEmpty()) {
return ImmutableList.of();
}
final Builder<T> builder = ImmutableList.builder();
final MultiGetResponse response = client
.prepareMultiGet()
.add(index, type, ids)
.execute()
.actionGet();
for(final MultiGetItemResponse item : response.getResponses()) {
final GetResponse get = item.getResponse();
if(get.isSourceEmpty()) {
continue;
}
final String json = get.getSourceAsString();
final T entity = deserializer.apply(json);
builder.add((T) entity.withId(get.getId()));
}
return builder.build();
}
示例9: testMultiGet
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
@Test
public void testMultiGet() throws Exception {
//first, INDEX two values
Map<String, String> map = createIndexedData();
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "1");
template.requestBodyAndHeaders("direct:start", map, headers, String.class);
headers.clear();
headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "facebook");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "status");
headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "2");
template.requestBodyAndHeaders("direct:start", map, headers, String.class);
headers.clear();
//now, verify MULTIGET
headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_MULTIGET);
Item item1 = new Item("twitter", "tweet", "1");
Item item2 = new Item("facebook", "status", "2");
Item item3 = new Item("instagram", "latest", "3");
List<Item> list = new ArrayList<Item>();
list.add(item1);
list.add(item2);
list.add(item3);
MultiGetResponse response = template.requestBodyAndHeaders("direct:start", list, headers, MultiGetResponse.class);
MultiGetItemResponse[] responses = response.getResponses();
assertNotNull("response should not be null", response);
assertEquals("response should contains three multiGetResponse object", 3, response.getResponses().length);
assertEquals("response 1 should contains tweet as type", "tweet", responses[0].getResponse().getType().toString());
assertEquals("response 2 should contains status as type", "status", responses[1].getResponse().getType().toString());
assertFalse("response 1 should be ok", responses[0].isFailed());
assertFalse("response 2 should be ok", responses[1].isFailed());
assertTrue("response 3 should be failed", responses[2].isFailed());
}
示例10: getMetric
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
@Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, int poolType) {
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
long timeBucket = startTimeBucket;
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType;
prepareMultiGet.add(MemoryPoolMetricTable.TABLE, MemoryPoolMetricTable.TABLE_TYPE, id);
}
while (timeBucket <= endTimeBucket);
JsonObject metric = new JsonObject();
JsonArray usedMetric = new JsonArray();
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
metric.addProperty("max", ((Number)response.getResponse().getSource().get(MemoryPoolMetricTable.COLUMN_MAX)).longValue());
metric.addProperty("init", ((Number)response.getResponse().getSource().get(MemoryPoolMetricTable.COLUMN_INIT)).longValue());
usedMetric.add(((Number)response.getResponse().getSource().get(MemoryPoolMetricTable.COLUMN_USED)).longValue());
} else {
metric.addProperty("max", 0);
metric.addProperty("init", 0);
usedMetric.add(0);
}
}
metric.add("used", usedMetric);
return metric;
}
示例11: getMetric
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
@Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap) {
MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
int i = 0;
long timeBucket = startTimeBucket;
do {
timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1);
String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap;
prepareMultiGet.add(MemoryMetricTable.TABLE, MemoryMetricTable.TABLE_TYPE, id);
}
while (timeBucket <= endTimeBucket);
JsonObject metric = new JsonObject();
JsonArray usedMetric = new JsonArray();
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
metric.addProperty("max", ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_MAX)).longValue());
metric.addProperty("init", ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_INIT)).longValue());
usedMetric.add(((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_USED)).longValue());
} else {
metric.addProperty("max", 0);
metric.addProperty("init", 0);
usedMetric.add(0);
}
}
metric.add("used", usedMetric);
return metric;
}
示例12: flush
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
private void flush() {
MultiGetResponse multiGetItemResponse = request.execute().actionGet();
for(MultiGetItemResponse response : multiGetItemResponse.getResponses()) {
if (response.isFailed()) {
logger.error("Get failed: " + response.getFailure().getMessage());
}
Metric metric = request.metrics.get(response.getId());
if (response.isFailed() || !response.getResponse().isExists()) {
final String[] parts = metric.getPath().split("\\.");
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < parts.length; i++) {
if (sb.toString().length() > 0) {
sb.append(".");
}
sb.append(parts[i]);
try {
bulkProcessor.add(new IndexRequest(index, type, metric.getTenant() + "_" + sb.toString()).source(
XContentFactory.jsonBuilder().startObject()
.field("tenant", metric.getTenant())
.field("path", sb.toString())
.field("depth", (i + 1))
.field("leaf", (i == parts.length - 1))
.endObject()
));
} catch (IOException e) {
logger.error(e);
}
}
}
}
request = new MetricMultiGetRequestBuilder(client, index, type);
}
示例13: syncAcl
import org.elasticsearch.action.get.MultiGetResponse; //导入方法依赖的package包/类
private void syncAcl(OpenshiftRequestContext context) {
LOGGER.debug("Syncing the ACL to ElasticSearch");
try {
lock.lock();
LOGGER.debug("Loading SearchGuard ACL...");
final MultiGetRequest mget = new MultiGetRequest();
mget.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true"); //header needed here
mget.refresh(true);
mget.realtime(true);
mget.add(searchGuardIndex, SEARCHGUARD_ROLE_TYPE, SEARCHGUARD_CONFIG_ID);
mget.add(searchGuardIndex, SEARCHGUARD_MAPPING_TYPE, SEARCHGUARD_CONFIG_ID);
SearchGuardRoles roles = null;
SearchGuardRolesMapping rolesMapping = null;
MultiGetResponse response = client.multiGet(mget).actionGet();
for (MultiGetItemResponse item : response.getResponses()) {
if(!item.isFailed()) {
if(LOGGER.isDebugEnabled()){
LOGGER.debug("Read in {}: {}", item.getType(), XContentHelper.convertToJson(item.getResponse().getSourceAsBytesRef(), true, true));
}
switch (item.getType()) {
case SEARCHGUARD_ROLE_TYPE:
roles = new SearchGuardRoles().load(item.getResponse().getSource());
break;
case SEARCHGUARD_MAPPING_TYPE:
rolesMapping = new SearchGuardRolesMapping().load(item.getResponse().getSource());
break;
}
}else {
LOGGER.error("There was a failure loading document type {}", item.getFailure(), item.getType());
}
}
if(roles == null || rolesMapping == null) {
return;
}
LOGGER.debug("Syncing from cache to ACL...");
RolesMappingSyncStrategy rolesMappingSync = documentFactory.createRolesMappingSyncStrategy(rolesMapping);
rolesMappingSync.syncFrom(cache);
RolesSyncStrategy rolesSync = documentFactory.createRolesSyncStrategy(roles);
rolesSync.syncFrom(cache);
writeAcl(roles, rolesMapping);
} catch (Exception e) {
LOGGER.error("Exception while syncing ACL with cache", e);
} finally {
lock.unlock();
}
}