前言;
es整合hbase实现二级索引的目的,只要是因为hbase不具备全文检索,只有rowkey是全局的唯一标识,在大量数据的前提下,想要根据字段进行检索,没办法利用rowkey就会出现效率低下的情况.刚好es具备全文检索的优良传统,两个优秀的框架注定是要擦出点火花来的.
设计思想: 在es中存储标题,在hbase 中存储正文
实现思路:
1.使用代码解析excel,读取excel的内容
2.将读取到的内容保存到es和hbase中去
3.搜索es中的字段,然后选择详细信息
4.通过hbase显示具体文件内容
一:在es中构建索引库
PUT /articles
{
"settings":{
"number_of_shards":3, //分片个数
"number_of_replicas":1, //副本个数
"analysis" : {
"analyzer" : {
"ik" : { //ik分词器
"tokenizer" : "ik_max_word" //分词器
}
}
}
},
"mappings":{
"article":{
"dynamic":"strict", //动静态
"_source": { //字段来源
"includes": [
"id","title","from","readCounts","times" //包含字段
],
"excludes": [ //不包含字段
"content" //不包含文章内容
]
},
"properties":{ //属性
"id":{"type": "keyword", "store": true}, //id,keyword类型,存储
//标题,text类型,存储,索引存储,使用ik分词器
"title":{"type": "text","store": true,"index" : true,"analyzer": "ik_max_word"},
//from字段, keyword类型,存储
"from":{"type": "keyword","store": true},
//readcounts字段,integer类型,存储
"readCounts":{"type": "integer","store": true},
//文章内容,text类型,不存储,不做索引
"content":{"type": "text","store": false,"index": false},
//时间,keyword类型,不做索引
"times": {"type": "keyword", "index": false}
}
}
}
}
二:创建maven工程,导入依赖
<dependencies>
<!--解析excel文件-->
<dependency>
<groupId>org.apache.poi</groupId>
<artif