100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 搜索引擎之ElasticSearch(es)入门学习 ELK 和 beats

搜索引擎之ElasticSearch(es)入门学习 ELK 和 beats

时间:2019-08-17 01:01:46

相关推荐

搜索引擎之ElasticSearch(es)入门学习 ELK 和 beats

好记星不如烂笔头,这里记录平时工作中用到的东西,不喜可以留言。

一、ElasticSearch为啥要用

ElasticSearch简称es是一个ElasticSearch是一个分布式,高性能、高可用、可伸缩的搜索和分析系统 。可以当做一个上层数据库来使用和关系数据库和Nosql有一定区别和相似性。其他搜索引擎,Lucene(Es底层)、Apache Solr (底层Lucene)。使用es的几个原因:

关系型数据库模糊搜索不足索引,会全表扫描非常慢。%关键词%这种搜索会非常慢。主:关系型数据库支持的是%关键词,搜索非常快。关系型数据库不支持全文搜索分词,eg 我想baidu搜索电影碟中谍-全面瓦解的时候,不小心打错了,打成了全瓦解,es就可以根据分词搜索出来这个电影。eg 企查查网站搜索的时候, 打成了千穆 上海,es也能搜索出来所有的千穆相关的公司。eg 启信宝,搜索的时候深圳特斯拉, es能搜索出来 几十个包含 深圳 和 特斯拉 相关的公司

在比如:搜索 上海千穆计算机xxx, 打成了千穆 上海,es也能搜索出来的。

3. 数据分析、日志分析, PB级别可以毫秒级搜索,自带分析能力

4. mongo不支持restful api, 底层使用BSON放数据,es使用json

5. 看看阿里云上面大数据里面就是 ElasticSearch

6.ELKB是什么?ELK(ElasticSearch, logstash, kibana)技术栈的版本统一,免的给用户带来混乱。kibana是一个可视化的形式工具,用来检索和图形化es。

7.beats是一个专门的数据采集工具,是 logstash的轻量级版本

数据采集程序:beats

可视化工具:grafana

监控:promethues

引用1:大白话ElasticSearch是什么以及应用场景

引用2:Springboot + ElasticSearch 构建博客检索系统 [慕课网]

引用3:ElasticSearch入门 [慕课网 瓦力]

引用4 ELK和beats ELK和beats

1 Es简单介绍

java开发,生产使用es6,jdk8+, 提供统一的restful接口访问能力elasticSearch配套工具,kibana(web界面操作es)、logstash同步中间件 mysql和es数据、elasticsearch head插件 类似kibaba 非官网插件。关系型数据库和es对比

Mysql: Select * from user.user_info where name = ‘张三’;

ES: Get /user/user_info/_search?q=name:张三

ES7: 重大特点,去掉了Type

2 ES数据同步中间件

数据同步分为两种,全量和后期增量(新增、修改)同步有:代码层在修改mysql的时候,同步更新es(缺点耦合,模块多很难维护);数据库层利用mysql binlog订阅,把es当做一个客户端; 使用 logstash配置mysql和es数据源并制定表格进行复制,支持多表。logstash-input-jdbc同时同步多个表 /xuwenjin/p/8989043.html

3 springboot集成Es

springboot增加es starter, 增加es 地址和端口9200

4 es分词插件

es默认分词对中文支持非常差,我们一般会安装第三方中文分词插件,比如“我是中国人”,看分词插件如何分词

5 es免费资源课程

imooc ElasticSearch入门imooc Springboot + ElasticSearch 构建博客检索系统

二.Es安装

es使用java开发,目前主流5+都可以,目前推荐使用6,最新的已经到7了。java使用java8+

2.1 es单实例安装、kibana安装

elaticsearch官方下载,到Download页面,下载老版本,请在该页面搜索"past releases"。目前我们使用6.x版本,太新的版本资料和生态(springboot2.0)不完善,我们按照6.8.6版本。

2.1.1 找到下载地址&安装es

官网历史版本下载地址:elasticsearch-6-8-3,当然官网下载慢到死的,下载要么通过香港服务器下载==》下载到本地、或者网上搜索 Elasticsearch 国内镜像下载站。

#1: Download and unzip Elasticsearch# yum list | grep -i elasticsearch # linux centos7 使用,但不推荐,我们自己下载安装把。wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.3.zip #下载zip版本、.tar.gz、.msi等wget /downloads/elasticsearch/elasticsearch-6.8.3.tar.gz # 下载国内地址# 说明 zip版本、tar.gz版,其实都一样,类似 tomcat, 平台通用的。这里进行解压unzip elasticsearch-6.8.3.zip #解压zip文件tar -vxf elasticsearch-6.8.3.tar.gz #解压 tar.gz文件

2: Runbin/elasticsearch(orbin\elasticsearch.baton Windows)

3: Runcurl http://localhost:9200/orInvoke-RestMethod http://localhost:9200with PowerShell,运行之后发现只是一个是json, 可以使用 postman 调用 restful接口。如何判断启动成功:打印started并且打印 对外监听端口9200。说明:9300是多个节点nodes之前的通讯接口。

4: 下载kibana进行进行图形界面化操作。kibana版本最好和es一致,至少大版本一致的。

elasticsearch docs guide cn

2.1.2 安装kibana(web应用,图像化操作es)

kibana一个图像化操作工具,是一个web程序。Elasticsearch是一个基于JSON的分布式搜索和分析引擎。Kibana可以让您的数据变的有型有样,是一个可扩展的用户界面。

kibana国内下载地址 , elaticsearch国外站点巨慢。下载可以用迅雷,可能快很多。使用5601进行访问。kibana官方下载地址 。最后推荐使用华为的mirrors ,搜索kibana选择版本进行下载。

# Download and unzip Kibana wget https://artifacts.elastic.co/downloads/kibana/kibana-6.8.3-windows-x86_64.zip #windowswget /kibana/6.8.3/kibana-6.8.3-darwin-x86_64.tar.gz # mac os wget /kibana/6.8.3/kibana-6.8.3-linux-x86_64.tar.gz # linux 64

2 Openconfig/kibana.ymlin an editor,Setelasticsearch.hoststo point at your Elasticsearch instance

3 Runbin/kibana(orbin\kibana.baton Windows)

4 Point your browser athttp://localhost:5601

所有kibana配置看

三.http restful和es进行交互

这里演示用postman 或者 curl 和 elastcisearch进行交互

## 查看索引,所有 索引,增加前缀;工具,直接可以提示 所有的索引## 查看索引,所有 索引,增加前缀;工具,直接可以提示 所有的索引##nuc_delivery#nuc_location#nuc_person_conn#nuc_sys_dept#sys_dict_data#vfic_vaccinate_process### 查询关键字,"" 会提示api关键词#{# "_index" : "nuc_positive_person",# "_type" : "_doc",# "_id" : "1474694263478657024",# "_score" : 4.3594446,# "_source" : {# "person_id" : null,# "person_name" : "刘xx",# "id_card" : "61272619XX07070010",# "person_phone" : "135XXXX8166",# "collect_org_name" : "西安市曲江新区新型冠状病毒感染的肺炎疫情防控指挥部",# "collect_location_name" : null,# "collect_time" : "-12-25T08:02:15+08:00",# "check_org_name" : "西安金域医学检验所有限公司",# "check_time" : "-12-25T18:43:07+08:00",# "swab_result" : "阳性",# "igg_result" : null,# "igm_result" : null,# "progress" : "0",# "create_time" : "-12-25T18:51:26+08:00",# "audit_time" : null,# "audit_user_id" : null,# "publish_time" : null,# "publish_user_id" : null,# "repeal_time" : null,# "repeal_user_id" : null,# "tube_code" : "-",# "collect_limit" : 1,# "collect_location_type" : null,# "add_time" : null# }### 1、查看所有的索引【表】名称GET /_cat/indices?format=json### 2、查看集群监控状态### kibana Dev Tools常用命令 /bigfacecat-h/p/14500466.htmlGET /_cat/health?format=json### 3、查看指定索引(表)中的一条数据document(column)详细数据### 3、 查看索引【nuc_sys_dept】中文档id【id】 = 100的文档GET nuc_sys_dept/_doc/100### 4、查看指定所有的总条数### Elasticsearch查询文档总数 /jamh/p/14975903.html#### 官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-count.html### GET /_cat/count/<target>### v=true: 是否包含列### 查看索引[表] 总条数GET /_cat/count/nuc_positive_person?v=true### 查看指定文件的的详情数据GET /nuc_positive_person/_doc/1462095480748158976 ### 按照搜索### 查询条件### 2.x 中文(Elasticsearch: 权威指南 » 基础入门 » 请求体查询 » 最重要的查询)(https://www.elastic.co/guide/cn/elasticsearch/guide/current/_most_important_queries.html#_match_all_查询) ### 7.x 英文 (Elasticsearch Guide [7.16] » Query DSL » Full text queries)(https://www.elastic.co/guide/en/elasticsearch/reference/current/full-text-queries.html) GET /_cat/count/nuc_positive_person?v=true{"query": {"match": {"id_card": "61063219901035"}}}###### 5、查询语句###### 5.1 query/match 【匹配】###### id_card 是文档中的字段GET /nuc_positive_person/_search{"query": {"match": {"id_card": "61063219901035"}}}###### 5.2 query/match/(query|fuzziness[中文:模糊性]) 【类似like匹配】### person_name:需要like的字段### query: person_name的查询条件,如:姓`张`(query)的用户, auto自动模糊fuzzinessGET /nuc_positive_person/_search{"query": {"match": {"person_name": {"query": "军","fuzziness": "auto"}}}}###### 5.3 范围(range)查询,日期、数字或字符串字## https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_ranges### 范围查询 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html### 查询 采样上线 collect_limit >= 5 and collect_limit <= 10# query: 查询, range:执行范围查询# sort: 指定排序规则# from: 指定分页start# from: 指定分页size# aggs: 聚合函数 # aggs: avg: 指定字段平均数# ElasticSearch - 聚合 aggs /weixin_40341116/article/details/81173016# ES之五:关于Elasticsearch查找相关的问题汇总(match、match_phrase、query_string和term) /duanxz/p/3508338.html GET /nuc_positive_person/_search{"query": {"range": {"collect_limit": {"gte": 5,"lte": 10,"boost": 2.0}}},"sort": [{"collect_time": {"order": "desc"}}],"aggs": {"my_avg_collect_limit": {"avg": {"field": "collect_limit"}}}, "from": 0,"size": 2}###### 5.4 范围(range)查询,日期## 采样时间:collect_time >gte and <= nowGET /_cat/count/nuc_positive_person?v=true{"query": {"range": {"collect_time": {"time_zone": "+08:00", "gte": "-12-31T00:00:00", "lte": "now" }}}}############################################################### 6.核算检测系统,数据量查询### nuc_person_query #人员信息索引(nuc_person)### nuc_tube_person 已经废弃xxx### nuc_tube ## 试管 db(nuc_tube)### nuc_tube_person_conn_new ################################################GET /_cat/count/nuc_tube?v=true{"query": {"range": {"collect_time": {"time_zone": "+08:00", "gte": "-12-29T00:00:00+08:00", "lte": "-12-31T00:00:00+08:00" }}}}### 7.聚合查询 - 分组 ## ES 24 - 通过 Elasticsearch 实现聚合检索 (分组统计)### /shoufeng/p/11290669.html## Elasticsearch 5.4.3 聚合分组 /shoufeng/p/11290669.html### 查询一条信息GET /vfic_project/_search {"from": 0,"size": 1}### 查询总条数GET /_cat/count/vfic_project?v=true### field 字段,必须是指定的字段,否则报错。### 使用 部门进行分组GET /vfic_project/_search{"from": 0,"size": 1, "aggs": {"group_by_tags—deptId": {"terms": {"field": "dept_id"}}}}### 8、删除疫苗无效的数据##ES 16 - 增删改查Elasticsearch中的索引数据 (CRUD) ## /shoufeng/p/10701141.html#4--删除documentGET /_cat/count/vfic_vaccinate_process?v=true #26558256GET /_cat/count/vfic_vaccinate_processnew?v=true #0GET /vfic_vaccinate_process/_search {"from": 0,"size": 10,"query": {"match": {"person_id_card": "6110020503XXXX"}}}### 根据文档id进行查询GET vfic_vaccinate_process/_doc/2186576## 根据文档document的id 进行删除## 语法:DELETE index/type/idDELETE vfic_vaccinate_process/_doc/2043053

1、Elasticsearch: 权威指南 » 基础入门 » 请求体查询 » 最重要的查询

2、Elasticsearch Guide [7.16] » Query DSL » Full text queries

1:GET 查看所有的索引

curl -XGET http://localhost:9200/_all #查询所有的索引

2:PUT 创建一个索引-person

curl -XPUT http://localhost:9200/person #创建一个索引 person 人类

3:DELETE 删除一个索引

curl -XDELETE http://localhost:9200/person #删除一个索引

4:PUT 新增数据

# 新增一条 userid = 1 的用户 curl -H "Content-Type: application/json" -XPUT http://localhost:9200/person/_doc/1 -d '{"first_name":"John","last_name":"Smith","age":25,"about":"I love to go rock climbing","interests":["sports","music"]}' ### json格式化如下{"first_name":"John","last_name":"Smith","age":25,"about":"I love to go rock climbing","interests": ["sports", "music"],}# 新版本6.0x, 目前一个索引person【类似一个数据库】,只有一个type【类似一个表】,我们用官网推荐的_doc【目前一个索引里面只有一个type,我们统一用_doc】,或者自定义一个 user 来代表。1:是id=1的数据。/gshao/p/11010642.html

5:搜索数据

# 我们尝试搜索一条数据,搜索 person索引中 默认类型_doc中id=1的数据# person_idcurl -XGET http://localhost:9200/person/_doc/1# person_name (进阶搜索)curl -XGET http://localhost:9200/person/_doc/_search?q=first_name:john #_search系统搜索关键词

四.使用Kibana Dev Tools 操作es

这里演示用Kibana 和 elastcisearch进行交互, 其实和直接使用 curl 或者 postman都是一样的。这里提供了,智能的提示。

#搜索所有GET _all # 搜索 person, es6.0之后,官方推荐_doc可以不写GET /person/_doc/1# 在演示一个【结构化查询】DSL 语句写法# 这里,我们es6+,只有一个type,直接省略_doc# 查询语句是json# query 是查询,全文检索# book 需要返回bool类型# 【should】: 应该要做什么,类似sql 【or】# 【should】变成 【must】: 必须要,类似 sql 【and】# match 匹配,做具体的字段搜索, 可以是多个匹配条件。# last_name: 姓名是 Smith, about 爱好是: basketball# POST /person/_search{"query": {"bool": {"should": [{"match": {"last_name": "Smith"}},{"match": {"about": "basketball"}}]}}}

其他更多演示,进阶演示,见 【ES】ElasticSearch 结构化查询和过滤

五、数据同步Beats vs Canal

beats: 定时同步Canal: 实时同步

参加:Canal数据库日志解析消费

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。