日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Solr+Hbase多条件查(优劣互补)

發(fā)布時(shí)間:2023/12/15 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Solr+Hbase多条件查(优劣互补) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

為什么要使用solr+hbase組合:

某電信項(xiàng)目中采用HBase來存儲(chǔ)用戶終端明細(xì)數(shù)據(jù),供前臺(tái)頁面即時(shí)查詢。HBase無可置疑擁有其優(yōu)勢,但其本身只對(duì)rowkey支持毫秒級(jí)的快速檢索,對(duì)于多字段的組合查詢卻無能為力。針對(duì)HBase的多條件查詢也有多種方案,但是這些方案要么太復(fù)雜,要么效率太低,本文只對(duì)基于Solr的HBase多條件查詢方案進(jìn)行測試和驗(yàn)證。

solr+habse組合的原理:

基于Solr的HBase多條件查詢?cè)砗芎唵?#xff0c;將HBase表中涉及條件過濾的字段和rowkey在Solr中建立索引,通過Solr的多條件查詢快速獲得符合過濾條件的rowkey值,拿到這些rowkey之后在HBASE中通過指定rowkey進(jìn)行查詢。

環(huán)境

1.????????????? 已搭建好的hadoop集群,3節(jié)點(diǎn)hadoop測試集群(見文檔hadoop2.5完全分布式集群搭建)

2.????????????? hadoop集群之上搭建hbase集群(文檔中hadoop2.5分布式中已包含)

3.????????????? 已搭建好的solrcloud集群,3節(jié)點(diǎn)solrcloud集群(見文檔solrcloud分布式集群)

4.????????????? oracle中導(dǎo)入數(shù)據(jù)到hbase中(可以通過普通java代碼或mapreduce,也可以直接使用工具sqoop

5.????????????? 使用sqooporacle中的數(shù)據(jù)導(dǎo)入hbase

sqoop實(shí)現(xiàn)數(shù)據(jù)從oracle導(dǎo)入hdfs(hbase)

?

sqoop import --append --connect jdbc:oracle:thin:@192.168.0.20:1521:orcl --username yqdev --password yq --m 1 --table c_text --columns id,url,title --hbase-create-table --hbase-table c_text --hbase-row-key id --column-family textinfo
?

注:需要在hbase中先創(chuàng)建c_text表,創(chuàng)建列族textinfo;我只導(dǎo)入了id,url,title三列,其中idrowkey.

6.????????????? 創(chuàng)建索引

hbase中讀取數(shù)據(jù),將需要用作查詢字段添加索引到solr中(例如title

????

/*** create solrIndex * * @throws IOException* @throws SolrServerException*/public static void addIndex() throws IOException, SolrServerException {// hbaseScan scan = new Scan();scan.addFamily(Bytes.toBytes(FAMILY_NAME));// scan.setCaching(500);scan.setCacheBlocks(false);ResultScanner rs = table.getScanner(scan);System.out.println("start......");Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();Long totalCount = 0l;for (Result r : rs) {SolrInputDocument doc = new SolrInputDocument();doc.addField("id", new String(r.getRow()));for (KeyValue kv : r.raw()) {String fieldName = new String(kv.getQualifier());String fieldValue = new String(kv.getValue());if (fieldName.equalsIgnoreCase("id")|| fieldName.equalsIgnoreCase("title")|| fieldName.equalsIgnoreCase("url")) {doc.addField(fieldName, fieldValue);}docs.add(doc);}if (docs.size() >= 1000) {cloudSolrServer.add(docs);cloudSolrServer.commit();totalCount = totalCount + docs.size();docs = new ArrayList<SolrInputDocument>();System.out.println("already deal with : " + totalCount);}}}


?

7.????????????? 查詢測試

?????

/*** 1.query solrIndex pass some condition 2.query data from hbase pass rowkey* * @throws IOException* @throws SolrServerException*/public static void query() throws IOException, SolrServerException {Get get = null;List<Get> list = new ArrayList<Get>();SolrQuery query = new SolrQuery("title:基金");query.setStart(0);query.setRows(40);QueryResponse response = cloudSolrServer.query(query);SolrDocumentList docs = response.getResults();System.out.println("total:" + docs.getNumFound());System.out.println("query time:" + response.getQTime());//get rowkey from solrfor (SolrDocument doc : docs) {get = new Get(Bytes.toBytes((String) doc.getFieldValue("id")));list.add(get);}//order rowkey query data from hbasefor (Get gt : list) {Result result = table.get(gt);byte[] value = result.getValue("textinfo".getBytes(),"title".getBytes());System.out.println("title------- \t" + new String(value));}}


hbase+solr多條件查詢的設(shè)計(jì)方案:

(利用hbase的大數(shù)據(jù)存儲(chǔ)和solr的強(qiáng)大的索引,達(dá)到互補(bǔ)的效果)

基于SolrHBase多條件查詢?cè)砗芎唵?#xff0c;將HBase表中涉及條件過濾的字段和rowkeySolr中建立索引,通過Solr的多條件查詢快速獲得符合過濾條件的rowkey值,拿到這些rowkey之后在HBASE中通過指定rowkey進(jìn)行查詢。

?

參考:http://www.cnblogs.com/chenz/articles/3229997.html

總結(jié)

以上是生活随笔為你收集整理的Solr+Hbase多条件查(优劣互补)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。