目录
安装部署
ElasticSearch Logstash Kibana 下载:(这里应有尽有,ES7.9.1需要JDK1.8及以上环境)
我的目标
全文搜索多个shp图层中的数据。采用ElasticSearch 提供搜索服务,暂不考虑数据同步问题。
路线:shp数据通过PostGIS插件导入PostgreSql后,利用Logstash 导入ES中已构建的索引。
ElasticSearch
修改config\elasticsearch.yml,使得可通过IP等访问,默认仅可通过localhost访问
network.host: 0.0.0.0
cluster.initial_master_nodes: ["node-1"]
中文分词ik下载加压后放入ES\plugins文件加下;
执行bin/elasticsearch.bat
-
分词ik_smart测试
GET http://localhost:9200/_analyze
{
"text" : "青岛市实验小学",
"analyzer" : "ik_smart"
}
-
分词库修改
安装IK 分词后,修改文件:../elasticsearch-7.9.1-windows-x86_64\elasticsearch-7.9.1\plugins\elasticsearch-analysis-ik-7.9.1\config\IKAnalyzer.cfg.xml,"extra_address.dic“为添加的分词内容,同一级别目录下放置extra_address.dic,这里添加的是路名等词语。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="ext_dict">extra_address.dic</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<!-- <entry key="remote_ext_dict">words_location</entry> -->
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
重启ES,测试分词,成功:
-
拼音支持
- GitHub elasticsearch-analysis-pinyin 7.xThis Pinyin Analysis plugin is used to do conversion between Chinese characters and Pinyin. - GitHub - medcl/elasticsearch-analysis-pinyin at 7.xhttps://github.com/medcl/elasticsearch-analysis-pinyin/tree/7.x
- elasticsearch 支持拼音检索_es拼音搜索_weixin_42934205的博客-CSDN博客elasticsearch 支持拼音检索1.下载安装对应es版本的拼音分词器下载地址:https://github.com/medcl/elasticsearch-analysis-pinyin/releases?after=v6.8.0因为我用的是6.8.0版本的es,所以下载的是6.8.0版本的插件。2.安装在es的plugins目录下,创建pinyin文件夹,将拼音分词器解压到pinyin文件夹目录下,然后重启es3.测试插件效果get http://ip:port/_analyze_es拼音搜索https://blog.csdn.net/weixin_42934205/article/details/107985185
- 一些原理 :Elasticsearch:分词器中的 token 过滤器使用示例 - 掘金分词器在 Elasticsearch 的使用中非常重要。分词器中的过滤器可以帮我们对最终的分词进行处理,从而使得我们得到的最终分词会影响存储的大小和搜索的方式。在今天的文章中,我来分享一下一些常用的分https://juejin.cn/post/7143258163205603342
-
新建索引Index
ES7之后Index后不可有多个type,所以Index在这里对应数据表,默认type 为_doc
http://localhost:9200/juzhuxiaoqu/ PUT
{ "settings" : {
"index" : {
"analysis.analyzer.default.type": "ik_max_word"
}
},
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "ik_max_word"
},
"mtype": {
"type": "text"
},
"location": {
"type": "geo_shape"
}
}
}
}
logStash
利用LogStash导入PostgreSQL数据库中的记录
-
配置文件
config_jdbc_postgresql_JuzhuXiaoqu.conf,放在bin文件夹下
input {
stdin {
}
jdbc {
jdbc_connection_string => "jdbc:postgresql://localhost:5432/postgres"
jdbc_user => "postgres"
jdbc_password => "12345"
jdbc_driver_library => "D:\znn\software\ES_about\logstash-7.9.1\lib\jars\postgresql-42.2.16.jar"
jdbc_driver_class => "org.postgresql.Driver"
jdbc_paging_enabled => "true"
jdbc_page_size => "300000"
use_column_value => "true"
tracking_column => "gid"
statement => "SELECT gid as id, name, type as mtype,st_astext(ST_Transform(geom,4326) ) as location FROM public.juzhu_xiaoqu"
#type => "jdbc"
jdbc_default_timezone =>"Asia/Shanghai"
}
}
filter{
}
output {
elasticsearch {
#es服务器
hosts => ["localhost:9200"]
#ES索引名称
index => "juzhuxiaoqu"
#自增ID
document_id => "%{id}"
}
stdout {
codec => json_lines
}
}
-
启动
执行命令行:D:\znn\software\ES_about\logstash-7.9.1\bin>logstash -f config_jdbc_postgresql_JuzhuXiaoqu.conf
-
停止
Ctrl+C
-
查看Index状态
查看Index当前总数,以判断Index是否构建完成
http://127.0.0.1:9200/_cat/indices?v
Kibana
kibana作为Elastic 家族的可视化门面,功能很强大,
以上部署完成后,修改Kibana为中文版:
-
启动Kibana
kibana-7.9.1-windows-x86_64\config\kibana.yml最后一行添加:
i18n.locale: "zh-CN"
-
查看ES中索引
左侧Managerment->Stack Management ,左侧数据—>索引管理 可查看localhost ES 已创建的Index,
-
Map可视化
左侧Kibana—>索引模式可添加 ES中的Index ,此处添加的Index在左侧菜单—>Kibana —>maps 中可进行导入,将地理信息数据在地图中可视化
全文索引
景区Index 内搜索
GET http://localhost:9200/jingqu/_search
{
"query":{
"multi_match":{
"query":"银沙滩",
"analyzer": "ik_smart"
}
}
}
所有Index内搜索
http://localhost:9200/_search
{
"query":{
"multi_match":{
"query":"银沙滩",
"analyzer": "ik_smart"
}
}
}
异常
logstash 插入数据时候会丢数据,日志中无原因。可采用分块加入的方式。
初步摸索的方法,大家有更好的方法欢迎评论交流。