本文整理汇总了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());
}
示例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()));
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}
}
}
示例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;
}
示例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;
}