當前位置: 首頁>>代碼示例>>Java>>正文


Java MultiGetItemResponse類代碼示例

本文整理匯總了Java中org.elasticsearch.action.get.MultiGetItemResponse的典型用法代碼示例。如果您正苦於以下問題:Java MultiGetItemResponse類的具體用法?Java MultiGetItemResponse怎麽用?Java MultiGetItemResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MultiGetItemResponse類屬於org.elasticsearch.action.get包,在下文中一共展示了MultiGetItemResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: queryByMultiGet

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的package包/類
/**
 * 獲取多個對象(根據ID)
 *
 * @param transportClient
 * @throws IOException
 */
private static void queryByMultiGet(TransportClient transportClient) throws IOException {

	MultiGetResponse multiGetItemResponses = transportClient.prepareMultiGet()
			.add("product_index", "product", "1")
			.add("product_index", "product", "2")
			.add("product_index", "product", "3")
			.add("product_index", "product", "4")
			.add("product_index", "product", "5")
			.get();

	String resultJSON = null;
	for (MultiGetItemResponse multiGetItemResponse : multiGetItemResponses) {
		GetResponse getResponse = multiGetItemResponse.getResponse();
		if (getResponse.isExists()) {
			resultJSON = getResponse.getSourceAsString();
		}
	}
	logger.info("--------------------------------:" + resultJSON);
}
 
開發者ID:judasn,項目名稱:Elasticsearch-Tutorial-zh-CN,代碼行數:26,代碼來源:BaseDemo.java

示例2: toMultiGetResponse

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的package包/類
public MultiGetResponse toMultiGetResponse() {
    List<Map> docs = getAs(entityWrapper, "docs", List.class);
    MultiGetItemResponse[] itemResponses = new MultiGetItemResponse[docs.size()];
    for (int i = 0; i < docs.size(); i++) {
        Map<String, Object> doc = docs.get(i);
        MultiGetResponse.Failure failure = null;
        GetResponse getResponse = null;
        if (doc.containsKey("error")) {
            String index = getAsString(doc, "_index");
            String type = getAsString(doc, "_type");
            String id = getAsString(doc, "_id");
            String error = getAsString(doc, "error");
            failure = new MultiGetResponse.Failure(index, type, id, error);
        } else {
            getResponse = GetResponseAccessor.build(toGetResult(doc, doc));
        }
        MultiGetItemResponse itemResponse = new MultiGetItemResponse(getResponse, failure);
        itemResponses[i] = itemResponse;
    }
    return new MultiGetResponse(itemResponses);
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:22,代碼來源:ResponseWrapper.java

示例3: findDocuments

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的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;
}
 
開發者ID:bpatters,項目名稱:eservice,代碼行數:27,代碼來源:AbstractElasticsearchDAO.java

示例4: getTpsMetric

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的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;
}
 
開發者ID:apache,項目名稱:incubator-skywalking,代碼行數:23,代碼來源:InstanceMetricEsUIDAO.java

示例5: getRespTimeMetric

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的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;
}
 
開發者ID:apache,項目名稱:incubator-skywalking,代碼行數:27,代碼來源:InstanceMetricEsUIDAO.java

示例6: getMetric

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的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;
}
 
開發者ID:apache,項目名稱:incubator-skywalking,代碼行數:24,代碼來源:CpuMetricEsUIDAO.java

示例7: bulkFetchList

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的package包/類
private void bulkFetchList(Set<Key> stillToFetch, final GDSCallback<Map<Key, Entity>> callback) {
	MultiGetRequestBuilder requestBuilder = gds.getClient().prepareMultiGet();

	for (Key key : stillToFetch) {
		requestBuilder.add(gds.indexFor(key.kind), key.kind, key.id);
	}
	
	requestBuilder.execute(new ActionListener<MultiGetResponse>() {
		
		@Override
		public void onResponse(MultiGetResponse response) {
			Map<Key, Entity> resultMap = Collections.synchronizedMap(new HashMap<Key, Entity>());
			for (MultiGetItemResponse itemResponse : response.getResponses()) {
				Entity entity = new Entity(itemResponse.getType(), itemResponse.getResponse().getId(), itemResponse.getResponse().getSourceAsMap());
				resultMap.put(new Key(itemResponse.getType(), itemResponse.getId()), entity);
			}
			callback.onSuccess(resultMap, null);
		}
		
		@Override
		public void onFailure(Throwable e) {
			callback.onSuccess(null, e);
		}
	});
}
 
開發者ID:Ryan-ZA,項目名稱:async-elastic-orm,代碼行數:26,代碼來源:GDSLoaderImpl.java

示例8: getByIds

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的package包/類
@Override
public <T> List<T> getByIds(Class<T> clazz, List<String> ids) {
    String typeName = MappingProcessor.getIndexTypeName(clazz);
    if (logger.isDebugEnabled()) {
        logger.debug("Get objects by ids, class: {}, type: {}, ids: {}", clazz.getSimpleName(), typeName, ids);
    }
    MultiGetResponse responses = client.prepareMultiGet().add(getIndexName(), typeName, ids).get();
    List<T> results = new ArrayList<T>();
    if (responses != null) {
        for (MultiGetItemResponse response : responses) {
            if (response.getResponse() != null) {
                results.add(objectProcessor.fromJsonString(response.getResponse().getSourceAsString(), clazz));
            }
        }
    }
    return results;
}
 
開發者ID:kzwang,項目名稱:elasticsearch-osem,代碼行數:18,代碼來源:ElasticSearchSearcherImpl.java

示例9: loadAll

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的package包/類
@Override
public Map<String, Table> loadAll(Collection<String> keys) {
    logger.info("Load all called for multiple keys");
    MultiGetResponse response = elasticsearchConnection.getClient()
            .prepareMultiGet()
            .add(TABLE_META_INDEX, TABLE_META_TYPE, keys)
            .execute()
            .actionGet();
    Map<String, Table> tables = Maps.newHashMap();
    for (MultiGetItemResponse multiGetItemResponse : response) {
        try {
            Table table = objectMapper.readValue(multiGetItemResponse.getResponse().getSourceAsString(),
                    Table.class);
            tables.put(table.getName(), table);
        } catch (Exception e) {
            throw new RuntimeException("Error getting data for table: " + multiGetItemResponse.getId());
        }
    }
    logger.info("Loaded value count: " + tables.size());
    return tables;
}
 
開發者ID:Flipkart,項目名稱:foxtrot,代碼行數:22,代碼來源:TableMapStore.java

示例10: queryForObjects

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的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();
       }
   }
 
開發者ID:yamingd,項目名稱:argo,代碼行數:31,代碼來源:ElasticSearchTemplate.java

示例11: existBulk

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的package包/類
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;
}
 
開發者ID:yacy,項目名稱:yacy_grid_mcp,代碼行數:15,代碼來源:ElasticsearchClient.java

示例12: testThatSourceFilteringIsSupported

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的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());
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:41,代碼來源:SimpleMgetIT.java

示例13: assertMultiGetResponse

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的package包/類
private static void assertMultiGetResponse(MultiGetResponse multiGetResponse, int numDocs) {
    assertThat(multiGetResponse.getResponses().length, equalTo(numDocs));
    int i = 1;
    for (MultiGetItemResponse multiGetItemResponse : multiGetResponse) {
        assertThat(multiGetItemResponse.getIndex(), equalTo("test"));
        assertThat(multiGetItemResponse.getType(), equalTo("test"));
        assertThat(multiGetItemResponse.getId(), equalTo(Integer.toString(i++)));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:10,代碼來源:BulkProcessorIT.java

示例14: MultiGet

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的package包/類
private static void MultiGet(Client client) {

        MultiGetResponse response = client.prepareMultiGet()
                .add("twitter","tweet","2","1")
                .get();
        for(MultiGetItemResponse itemResponse:response){
            GetResponse getResponse = itemResponse.getResponse();
            if(getResponse.isExists()){
                System.out.println(getResponse.getSourceAsString());
            }
        }
    }
 
開發者ID:hs-web,項目名稱:hsweb-learning,代碼行數:13,代碼來源:ElasticSearch.java

示例15: mapResults

import org.elasticsearch.action.get.MultiGetItemResponse; //導入依賴的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;
}
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:13,代碼來源:UKResultMapper.java


注:本文中的org.elasticsearch.action.get.MultiGetItemResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。