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


Java GetResponse.getSourceAsMap方法代碼示例

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


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

示例1: test_get

import org.elasticsearch.action.get.GetResponse; //導入方法依賴的package包/類
private void test_get(final Client client, final String index,
        final String type, final String id, final byte[] hash1,
        final byte[] hash2, final byte[] hash3) {
    final GetResponse response = client
            .prepareGet(index, type, id)
            .setFields("_source", "minhash_value1", "minhash_value2",
                    "minhash_value3").execute().actionGet();
    assertTrue(response.isExists());
    final Map<String, Object> source = response.getSourceAsMap();
    assertEquals("test " + Integer.parseInt(id) % 100, source.get("msg"));

    final GetField field1 = response.getField("minhash_value1");
    final BytesArray value1 = (BytesArray) field1.getValue();
    assertEquals(hash1.length, value1.length());
    Assert.assertArrayEquals(hash1, value1.array());

    final GetField field2 = response.getField("minhash_value2");
    final BytesArray value2 = (BytesArray) field2.getValue();
    assertEquals(hash2.length, value2.length());
    Assert.assertArrayEquals(hash2, value2.array());

    final GetField field3 = response.getField("minhash_value3");
    final BytesArray value3 = (BytesArray) field3.getValue();
    assertEquals(hash3.length, value3.length());
    Assert.assertArrayEquals(hash3, value3.array());
}
 
開發者ID:sherlok,項目名稱:sherlastic,代碼行數:27,代碼來源:SherlokPluginTest.java

示例2: assertRealtimeGetWorks

import org.elasticsearch.action.get.GetResponse; //導入方法依賴的package包/類
void assertRealtimeGetWorks(String indexName) {
    assertAcked(client().admin().indices().prepareUpdateSettings(indexName).setSettings(Settings.builder()
            .put("refresh_interval", -1)
            .build()));
    SearchRequestBuilder searchReq = client().prepareSearch(indexName).setQuery(QueryBuilders.matchAllQuery());
    SearchHit hit = searchReq.get().getHits().getAt(0);
    String docId = hit.getId();
    // foo is new, it is not a field in the generated index
    client().prepareUpdate(indexName, "doc", docId).setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "bar").get();
    GetResponse getRsp = client().prepareGet(indexName, "doc", docId).get();
    Map<String, Object> source = getRsp.getSourceAsMap();
    assertThat(source, Matchers.hasKey("foo"));

    assertAcked(client().admin().indices().prepareUpdateSettings(indexName).setSettings(Settings.builder()
            .put("refresh_interval", IndexSettings.DEFAULT_REFRESH_INTERVAL)
            .build()));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:OldIndexBackwardsCompatibilityIT.java

示例3: test_get

import org.elasticsearch.action.get.GetResponse; //導入方法依賴的package包/類
private void test_get(final Client client, final String index,
        final String type, final String id, final byte[] hash1,
        final byte[] hash2, final byte[] hash3) {
    final GetResponse response = client.prepareGet(index, type, id)
            .setStoredFields(new String[] { "_source", "minhash_value1", "minhash_value2", "minhash_value3" }).execute()
            .actionGet();
    assertTrue(response.isExists());
    final Map<String, Object> source = response.getSourceAsMap();
    assertEquals("test " + Integer.parseInt(id) % 100, source.get("msg"));

    final DocumentField field1 = response.getField("minhash_value1");
    final BytesArray value1 = (BytesArray) field1.getValue();
    assertEquals(hash1.length, value1.length());
    Assert.assertArrayEquals(hash1, value1.array());

    final DocumentField field2 = response.getField("minhash_value2");
    final BytesArray value2 = (BytesArray) field2.getValue();
    assertEquals(hash2.length, value2.length());
    Assert.assertArrayEquals(hash2, value2.array());

    final DocumentField field3 = response.getField("minhash_value3");
    final BytesArray value3 = (BytesArray) field3.getValue();
    assertEquals(hash3.length, value3.length());
    Assert.assertArrayEquals(hash3, value3.array());
}
 
開發者ID:codelibs,項目名稱:elasticsearch-minhash,代碼行數:26,代碼來源:MinHashPluginTest.java

示例4: getMap

import org.elasticsearch.action.get.GetResponse; //導入方法依賴的package包/類
protected static Map<String, Object> getMap(GetResponse response) {
    Map<String, Object> map = null;
    if (response.isExists() && (map = response.getSourceAsMap()) != null) {
        map.put("$type", response.getType());
    }
    return map;
}
 
開發者ID:yacy,項目名稱:yacy_grid_mcp,代碼行數:8,代碼來源:ElasticsearchClient.java

示例5: parse

import org.elasticsearch.action.get.GetResponse; //導入方法依賴的package包/類
private ElasticSearchDoc parse(final GetResponse response) {
    ElasticSearchDoc result = null;
    if (response.isExists()) {
        final Map<String, Object> responseMap = response.getSourceAsMap();
        final String user = (String) responseMap.get(ElasticSearchDoc.Field.USER);
        final boolean deleted = (boolean) responseMap.get(ElasticSearchDoc.Field.DELETED);
        final long timestamp = (long) responseMap.get(ElasticSearchDoc.Field.TIMESTAMP);
        @SuppressWarnings("unchecked") final Object dto = metacatJson.parseJsonValue(
            response.getSourceAsBytes(),
            getClass(response.getType())
        );
        result = new ElasticSearchDoc(response.getId(), dto, user, deleted, timestamp);
    }
    return result;
}
 
開發者ID:Netflix,項目名稱:metacat,代碼行數:16,代碼來源:ElasticSearchUtilImpl.java

示例6: get

import org.elasticsearch.action.get.GetResponse; //導入方法依賴的package包/類
/**
 * Get document by id.
 * 
 * @param clazz
 *            Class of document.
 * @param id
 *            Document id.
 * @return Java bean.
 */
public <T> T get(Class<T> clazz, String id) {
	Mapping mapping = getMappingFromClass(clazz);
	GetResponse gr = client.prepareGet(index, mapping.getType(), id).get();
	if (!gr.isExists()) {
		return null;
	}
	Map<String, Object> props = gr.getSourceAsMap();
	return mapping.createBean(id, props);
}
 
開發者ID:michaelliao,項目名稱:es-wrapper,代碼行數:19,代碼來源:SearchableClient.java

示例7: getLastCheckTime

import org.elasticsearch.action.get.GetResponse; //導入方法依賴的package包/類
private Long getLastCheckTime() {
    GetResponse getResponse = client.prepareGet(riverIndexName, riverName.getName(), "_stat").get();
    if (getResponse.isExists()) {
        Map<String, Object> statMap = getResponse.getSourceAsMap();
        if (statMap.containsKey("lastChecked")) {
            return (Long) statMap.get("lastChecked");
        }
    }
    return 0l;
}
 
開發者ID:kzwang,項目名稱:elasticsearch-river-dynamodb,代碼行數:11,代碼來源:DynamoDbRiver.java

示例8: updateCanonicalIds

import org.elasticsearch.action.get.GetResponse; //導入方法依賴的package包/類
public void updateCanonicalIds(Id canonicalId, Iterable<Id> setIds) throws IndexException {
    ImmutableSet<GetResponse> setSources = resolveSet(setIds);
    BulkRequest bulkReq = Requests.bulkRequest();
    for (GetResponse response : setSources) {
        Map<String, Object> source = response.getSourceAsMap();
        if (source != null) {
            source.put(EsContent.CANONICAL_ID, canonicalId.longValue());
            IndexRequest req = Requests.indexRequest(indexName)
                    .id(Integer.toString((int) response.getSourceAsMap().get(EsContent.ID)))
                    .type(response.getType())
                    .source(response.getSourceAsMap());
            if (response.getType().equalsIgnoreCase(EsContent.CHILD_ITEM)) {
                req.parent(String.valueOf(source.get(EsContent.BRAND)));
            }
            bulkReq.add(req);
        }
    }
    if (bulkReq.numberOfActions() > 0) {
        BulkResponse resp = ElasticsearchUtils.getWithTimeout(
                esClient.bulk(bulkReq),
                requestTimeout
        );
        if (resp.hasFailures()) {
            throw new IndexException("Failures occurred while bulk updating canonical IDs: "
                    + resp.buildFailureMessage());
        }
    }
}
 
開發者ID:atlasapi,項目名稱:atlas-deer,代碼行數:29,代碼來源:EsUnequivalentContentIndexer.java

示例9: indexGetDocument

import org.elasticsearch.action.get.GetResponse; //導入方法依賴的package包/類
/**
 * Get document from inmemory client.
 * 
 * @param indexName
 * @param documentType
 * @param id
 * @return null if document doesn't exist, Map of Maps structure if exists.
 * 
 */
public Map<String, Object> indexGetDocument(String indexName, String documentType, String id) {
	GetResponse r = client.get((new GetRequest(indexName, documentType, id))).actionGet();
	if (r != null && r.isExists()) {
		return r.getSourceAsMap();
	}
	return null;

}
 
開發者ID:macanhhuy,項目名稱:dcp-api,代碼行數:18,代碼來源:ESRealClientTestBase.java

示例10: indexGetDocument

import org.elasticsearch.action.get.GetResponse; //導入方法依賴的package包/類
/**
 * Get document from in-memory client.
 * 
 * @param indexName
 * @param documentType
 * @param id
 * @return null if document doesn't exist, Map of Maps structure if exists.
 * 
 */
public Map<String, Object> indexGetDocument(String indexName, String documentType, String id) {
	GetResponse r = client.get((new GetRequest(indexName, documentType, id))).actionGet();
	if (r != null && r.isExists()) {
		return r.getSourceAsMap();
	}
	return null;

}
 
開發者ID:searchisko,項目名稱:searchisko,代碼行數:18,代碼來源:ESRealClientTestBase.java


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