当前位置: 首页>>代码示例>>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;未经允许,请勿转载。