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

来源:互联网 发布:java类设计工具 编辑:程序博客网 时间:2024/05/22 21:58

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类名改了,还要把包名改了,这样才会生效,安全一点,把路径也改了。
第二个坑,最好每个表一个文件夹。




0 0
原创粉丝点击