- 浏览: 349962 次
- 性别:
- 来自: 杭州
最新评论
-
penkee:
为何我启动 zookKeeper bookie 10 不能创 ...
bookkeeper安装及测试体验 -
Golden-jin:
1楼也好时髦呀
bookkeeper简单分析 -
xGss2000:
要是减少到300个 region,block就0.04s了。话 ...
多region下的hbase写入问题 -
brandom520:
请问lz,我从hbase0.94版本上的数据导入到0.96.1 ...
在不同版本hdfs集群之间转移数据 -
huanghaifeng1990:
您好,我想请问一下,我执行了会发生OOM溢出的Deflater ...
perftools查看堆外内存并解决hbase内存溢出
hbasene(https://github.com/akkumar/hbasene)是开源项目,在hbase存储上封装使用Lucene来创建索引,代码API非常简单,熟悉lucene的朋友可以很方便地创建。
以下为测试代码,完成读取一张hbase上记录url和用户id的表,对其创建索引并进行简单的基于url的索引的代码。当取到search的结果后,就可以拿到想要的数据了。由于分词后将原始内容进行了反向索引,所以匹配就转化为了查询,速度相当快。
其中getDocumentFromHTable为读取一张hbase上己有的表,将url字段提取出来创建content索引。
创建索引的实质是用了HBaseIndexWriter和HBaseIndexReader两个分别继承自IndexWriter和IndexReader的类来做索引的读取和写入。同时使用了HBaseIndexStore来做存储。
而创建索引使用的分词等仍然是使用标准的lucene API。
注意hbasene使用的是hbase-0.20.5,需要修改少量源代码才能运行在0.90.x以上的版本中。
这里对创建索引表使用到的结构做下简单的说明,因为是lucene入门级水平,所以各位请尽管拍砖讨论。
索引表由以下几个CF构成:
以下为运行后查看表的中情况:
以下为测试代码,完成读取一张hbase上记录url和用户id的表,对其创建索引并进行简单的基于url的索引的代码。当取到search的结果后,就可以拿到想要的数据了。由于分词后将原始内容进行了反向索引,所以匹配就转化为了查询,速度相当快。
其中getDocumentFromHTable为读取一张hbase上己有的表,将url字段提取出来创建content索引。
创建索引的实质是用了HBaseIndexWriter和HBaseIndexReader两个分别继承自IndexWriter和IndexReader的类来做索引的读取和写入。同时使用了HBaseIndexStore来做存储。
而创建索引使用的分词等仍然是使用标准的lucene API。
注意hbasene使用的是hbase-0.20.5,需要修改少量源代码才能运行在0.90.x以上的版本中。
这里对创建索引表使用到的结构做下简单的说明,因为是lucene入门级水平,所以各位请尽管拍砖讨论。
索引表由以下几个CF构成:
- fm.sequence: 记录sequenceId,在执行createLuceneIndexTable时需要写死该CF的row为sequenceId,qulifier为qual.sequence,值为-1。可以不用理会
- fm.doc2int: DocumentId,每个document都会有一个这样的id,如果Field.Store设置为YES,则能在索引表中查询到该id并得到完整的内容。
- fm.termVector: 向量偏移,用于模糊查找,记录偏移量等信息
- fm.termFrequency:分词后的关键词在每个document中出现的频率,qulifier为documentId,value为出现次数
- fm.fields:记录了content内容,row为documentId,value为document的全文内容,它和fm.docint是相反的,后者是反向索引。
- fm.payloads:扩展CF,目前还没有用到
import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.HTablePool; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; import org.apache.lucene.util.Version; import org.hbasene.index.HBaseIndexReader; import org.hbasene.index.HBaseIndexStore; import org.hbasene.index.HBaseIndexWriter; public class test{ static final String indexName = "myindex"; static final String dataName = "t1"; public static void main(String[] args) throws IOException { try{ Configuration conf = HBaseConfiguration.create(); //hbase-site.xml in the classpath conf.set("hbase.rootdir", "hdfs://192.168.0.1:9000/hbase"); conf.set("hbase.zookeeper.quorum", "192.168.0.1,192.168.0.2,192.168.0.3"); HTablePool tablePool = new HTablePool(conf, 10); HBaseIndexStore.createLuceneIndexTable(indexName, conf, true); //Write HBaseIndexStore hbaseIndex = new HBaseIndexStore(tablePool, conf, indexName); HBaseIndexWriter writer = new HBaseIndexWriter(hbaseIndex, "content"); //Name of the primary key field. getDocument(writer); writer.close(); //Read/Search IndexReader reader = new HBaseIndexReader(tablePool, indexName, "f"); IndexSearcher searcher = new IndexSearcher(reader); Term term = new Term("content", "item.taobao.com"); TermQuery termQuery = new TermQuery(term); TopDocs docs = searcher.search(termQuery, 3); searcher.close(); }catch(IOException e){ e.printStackTrace(); throw e; } } private static void getDocument(HBaseIndexWriter writer) throws IOException{ Document doc = new Document(); doc.add(new Field("content", "some content some dog", Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(doc, new StandardAnalyzer(Version.LUCENE_30)); doc = new Document(); doc.add(new Field("content", "some id", Field.Store.NO, Field.Index.ANALYZED)); writer.addDocument(doc, new StandardAnalyzer(Version.LUCENE_30)); doc = new Document(); doc.add(new Field("content", "hot dog", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS)); writer.addDocument(doc, new StandardAnalyzer(Version.LUCENE_30)); } private static void getDocumentFromHTable(HTablePool tablePool, HBaseIndexWriter writer) throws IOException { Document doc = new Document(); Scan scan = new Scan(); HTable htable = (HTable)tablePool.getTable(dataName); ResultScanner results = htable.getScanner(scan); Result row; while((row = results.next()) != null){ doc = new Document(); String value = new String(row.getValue("test".getBytes(), null)); String url = value.split("\"")[2]; doc.add(new Field("content", url, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_OFFSETS)); writer.addDocument(doc, new StandardAnalyzer(Version.LUCENE_30)); } } }
以下为运行后查看表的中情况:
评论
5 楼
xchd
2013-12-29
你好,可以发跟demo吗?谢谢。我修改源码的错误之后,发现数据不能插入hbase中。谢谢。xchd-3@163.com
4 楼
fncj
2013-02-27
注意hbasene使用的是hbase-0.20.5,需要修改少量源代码才能运行在0.90.x以上的版本中。
您好,你有修改后的代码吗?能否发我一份?170466123#qq.com
您好,你有修改后的代码吗?能否发我一份?170466123#qq.com
3 楼
mls626
2012-11-07
请问楼主,如何获取到 hbasene 的 jar 包,官网上给出的源代码有些问题,这是我的邮箱 spring_ssh@163.com 非常感谢
2 楼
cnrainbing
2012-03-31
楼主你能否提供一下完整的例子,hbasene.jar 我们怎么获取啊,很急我的邮箱rainbing@live.com
1 楼
eryk
2011-08-24
您好,请问一下如果升级hbase版本到0.90 需要修改什么地方?我的qq:47020113,很急,请联系我,谢谢
发表评论
-
lease引发的血案
2011-12-19 23:01 6115今天线上出现了一个故障惊出一身冷汗,经过查明原来是lease引 ... -
hbase写被block住的典型案例分析
2011-11-10 22:32 5880今天一个线上集群出现莫名奇妙不能写入数据的bug,lo ... -
在不同版本hdfs集群之间转移数据
2011-10-26 18:56 7146本文仅供记录一下程序心得: 很多人会有这样一个需求:将 ... -
hbase中的deleteColumn
2011-10-26 16:59 5108Delete类的接口有两个方法:deleteColum ... -
splitlog期间丢失数据的问题
2011-10-18 22:26 3653splitlog是保证在重启或rs挂掉后,恢复hlog ... -
hbase中多次加载root及meta的bug
2011-10-18 22:24 3120执行以下case可以见到root或meta被加载两次: ... -
两次hbase丢失数据的故障及原因分析
2011-10-18 18:12 16590hbase的稳定性是近期社区的重要关注点,毕竟稳定的系 ... -
hbase中regionserver常见的oom原因分析
2011-09-15 10:40 8972首先要清楚reginserver中内存是如何使用的。 ... -
hbase的export与import工具
2011-09-01 08:01 11237hbase提供了导出表的方案,将指定的表导出到HDFS ... -
disable table失败的处理
2011-08-30 20:02 4290相信每一个维护hbase集群的运维人员一定碰到过dis ... -
使用zookeeper管理多个hbase集群
2011-08-16 15:30 18076zookeeper是hbase集群的"协调器 ... -
一次奇异的getRegionInfo异常定位
2011-08-10 19:55 2481今天在线上环境的 ... -
多region下的hbase写入问题
2011-08-10 13:13 9199最近在集群上发现hbase写入性能受到较大下降,测试环 ... -
hbase-0.90.4的主要更新
2011-07-15 22:15 2770apache邮件列表中提 ... -
hbase中缓存的优先级
2011-06-15 16:30 4083今天同事问到hbase中in-memory属性的作用, ... -
hbase交流记录
2011-06-02 10:34 3491前几天和公司的同事杨传辉(http://www.nosqlno ... -
secondary index for hbase
2011-05-07 23:05 5745最近因为业务需求 ... -
hdfs上的append测试
2011-05-04 23:42 6482hbase在写入数据之前会先写hlog,hlog目前是se ... -
hbase写入性能影响续
2011-04-18 15:28 10551今天发现hbase在写入一张新表时,写入过程中时常会出 ... -
hbase中的缓存的计算与使用
2011-04-13 20:20 8298hbase中的缓存分了两层:memstore和b ...
相关推荐
hbase 资源合集 hbase 企业应用开发实战 权威指南 hbase 实战 hbase 应用架构
Indexer 索引和搜索不会影响 HBase 运行的稳定性和 HBase 数据写入的吞吐量,因为索引和 搜索过程是完全分开并且异步的。Lily HBase Indexer 在 CDH5 中运行必须依赖 HBase、 SolrCloud 和 Zookeeper 服务。
利用hadoop的mapreduce和Hbase,基于lucene做的简单的搜索引擎 ## 基本介绍 - InjectDriver 将本地的url注入到hbase数据库中等待下一步执行 - FetchDriver 负责抓取url对应的网页内容 - ParserUrlDriver 解析所抓取...
HBASE基础应用的介绍。一个初步认知的pdf。
利用hadoop的mapreduce和Hbase,基于lucene做的简单的搜索引擎 基本介绍 InjectDriver 将本地的url注入到hbase数据库中等待下一步执行 FetchDriver 负责抓取url对应的网页内容 ParserUrlDriver 解析所抓取网页内容...
public class IndexBuilder3 extends Configured{ public static class MapperIndex extends TableMapper,Put>{ private String tableName; private String columnFamily;...// 该列对应的索引表名字
Hbase应用开发实验报告及代码;(1) 列出HBase所有的表的相关信息,例如表名、创建时间等;(2) 在终端打印出指定的表的所有记录数据;(3) 向已经创建好的表添加和删除指定的列族或列;(4) 清空指定的表的所有...
HBase企业应用开发】工作中自己总结的Hbase文档,非常全面!
Hadoop+HBase+Hive+lucene分布式搜索引擎分析系统
本方案主要参照了华为公布的HBase二级索引实现方案。基于hadoop平台,设计了Hbase的二级索引机制。
HBase企业应用开发实战-马延辉 孟鑫HBase企业应用开发实战-马延辉 孟鑫HBase企业应用开发实战-马延辉 孟鑫HBase企业应用开发实战-马延辉 孟鑫HBase企业应用开发实战-马延辉 孟鑫
华为大数据培训之HBase应用开发: 1.HBase应用场景 2.HBase应用开发流程 3.应用开发案例分析 4.表设计指导 5.常用开发接口示例 6.应用开发实践
企业应用开发实战中文版,共包括三个压缩文件(1-HBase企业应用开发实战.part1.rar,1-HBase企业应用开发实战.part2.rar,1-HBase企业应用开发实战.part3.rar)
HBase企业应用开发实战HBase企业应用开发实战HBase企业应用开发实战
Hbase全称为Hadoop Database,即Hbase是Hadoop的数据库,是一个分布式的存储系统。Hbase利用Hadoop的HDFS作为其文件存储系统,利用Hadoop的MapReduce来处理Hbase中的海量数据。利用zookeeper作为其协调工具。 本篇...
该索引方案是一种较好的实现方式,而且是现有很少的hbase索引实现方法
HBase作为Google发表BigTable论文的开源实现版本,是一种分布式列式存储的数据库,构建在HDFS之上的NoSQL数据库,非常适合大规模实时查询,因此HBase在实时计算领域使用非常广泛。可以实时写HBase,也可以利用...
Phoniex 可以让开发者在HBase数据集上使用SQL查询。Phoenix查询引擎会将SQL查询转换为一个或多个HBase scan,并编排执行以生成标准的JDBC结果集,对于简单查询来说,性能甚至胜过Hive。 标签:Phoniex