您的位置:首页 > 其它

对:通过HBase Observer同步数据到ElasticSearch的使用情况

2017-03-14 16:14 387 查看
1、需要把client.prepareUpdate 接口 替换成 client.prepareIndex 接口

@Override
public void postPut(ObserverContext<RegionCoprocessorEnvironment> e, Put put, WALEdit edit, Durability durability) throws IOException {
try {
String indexId = new String(put.getRow());
NavigableMap<byte[], List<Cell>> familyMap = put.getFamilyCellMap();
Map<String, Object> json = new HashMap<String, Object>();
for (Map.Entry<byte[], List<Cell>> entry : familyMap.entrySet()) {
for (Cell cell : entry.getValue()) {
String key = Bytes.toString(CellUtil.cloneQualifier(cell));
String value = Bytes.toString(CellUtil.cloneValue(cell));
json.put(key, value);
}
}
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
bulkRequestBuilder.add(client.prepareIndex(Config.indexName, Config.typeName, indexId).setSource(json));
BulkResponse bulkResponse;
bulkResponse = bulkRequestBuilder.execute().actionGet();
} catch (Exception ex) {
LOG.error(ex);
}
}

2、使用的是hbase1.0.2
对于::

修改Java代码后,上传到HDFS的jar包文件必须和之前不一样,否则就算卸载掉原有的coprocessor再重新安装也不能生效
如果你有多个表对多个索引/类型的映射,每个表所加载Observer对应的jar包路径不能相同,否则ElasticSearch会串数据
这两个坑:
修改了java代码,不止要把DataSyncObserver类名改了,还要把包名改了,这样才会生效,安全一点,把路径也改了。
第二个坑,最好每个表一个文件夹。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: