ElasticSearch+ Logstash +Kibana 部署记录 ;数据导入;shp 数据存储于PostgreSql ,PostGIS 地理引擎,实现全文搜索

目录

安装部署

我的目标

ElasticSearch

分词ik测试

分词库修改

新建索引Index

logStash

配置文件

启动

停止

查看Index状态

Kibana

启动Kibana

查看ES中索引

Map可视化

全文索引


安装部署

ElasticSearch Logstash Kibana 下载:(这里应有尽有,ES7.9.1需要JDK1.8及以上环境)

下载中心 - Elastic 中文社区

我的目标

全文搜索多个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,测试分词,成功:

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 插入数据时候会丢数据,日志中无原因。可采用分块加入的方式。

初步摸索的方法,大家有更好的方法欢迎评论交流。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值