Kibana⼊门与ES⼊门ES整合IK中⽂分词器
kibana是node开发的。
1.下载安装
0.官⽹步骤如下
1. 下载
也是在官⽹下载kibana,例如我下载的是:(kibana是nodejs写的,依赖⽐较多,所以解压缩会⽐较慢)
2. 解压安装
3.启动
执⾏ bin/kibana.bat,启动后⽇志如下:
log [14:32:25.598] [info][server][Kibana][http] http server running at localhost:5601
4. 访问kibana⾸页
常⽤功能如下:
Discover: 数据查看以及搜索
Visualize:数据可视化制作
Dashboard:仪表盘制作
Devtools:开发者⼯具
Management:配置
5.kibana配置详解
主要是l,注意配置项有:
server.host/server.port 访问kibana的地址和端⼝。如果需要开启外⽹访问需要更改该地址。默认是localhost:5601
elasticsearch.hosts: ["localhost:9200"] kibana放我的es的地址,默认是本地的9200端⼝
补充:今天我在另⼀个机⼦启动kibana的时候报错如下:
"warning","migrations","pid":6181,"message":"Another Kibana instance appears to be migrating the index. Waiting for that migration to complete. If no other Kibana instance is attempting migr 解决办法:
(1)停⽌kibana
(2)查看kibana相关索引
curl localhost:9200/.kibana*
(3)删除索引再次查看
C:\Users\Administrator>curl -XDELETE localhost:9200/.kibana*
{"acknowledged":true}
C:\Users\Administrator>curl localhost:9200/.kibana*
{}
(4)再次启动kibana即可
补充:kibana简单使⽤
0.先到kibana的设置建⽴Index pttern
1.表格展⽰ Discover ⾯板
该⾯板选择对应的pattern之后,默认是展⽰数据。点击左边选择对应的列即可展⽰成表格,如下:
2. 建⽴饼图-Visualize⾯板
(1)选择pie饼图,之后选择相应的index pattern
(2)例如选择查看每个thread对应的⽂档数量,相当于按thread分组后查询总数(参数设置好之后点击save保存即可)
2.ElasticSearch术语介绍与kibana⼊门
1.Elastic术语介绍
Document:⽂档数据,就是我们存在es中的⼀条数据
Index:索引。可以理解为mysql中的⼀个DB,⼀个数据库。所有的document都是存在⼀个具体的index中。
Type:Index下的数据类型。可以理解为mysql的⼀个表。 ES默认的是_doc。⽬前的是⼀个Index⼀个Type。(今天看公司⽤的应该是5.x版本的,⼀个index是⽀持多个
type的)
Field:字段,⽂档的属性。可以理解为mysql表中的列。
Query DSL:ES查询语法
2.ES中进⾏CRUD
这⾥我们使⽤Kibana的Devtools⼯具进⾏操作。
1.创建⼀个⽂档
POST /accounts/person/1
{
"name": "zhi",
"lastName": "qiao",
"job": "enginee"
}
返回结果如下:
#! Deprecation: [types removal] Specifying types in document index requests is deprecated, use the typeless endpoints instead (/{index}/_doc/{id}, /{index}/_doc, or /{index}/_create/{ {
"_index" : "accounts",
"_type" : "person",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
accounts就是索引,类型是person,插⼊的id是1,版本号是1.
2.读取⽂档
GET accounts/person/1
返回的结果如下:
#! Deprecation: [types removal] Specifying types in document get requests is deprecated, use the /{index}/_doc/{id} endpoint instead.
{
"_index" : "accounts",
"_type" : "person",
"_id" : "1",
"_version" : 2,
"_seq_no" : 1,
"_primary_term" : 1,
"found" : true,
"_source" : {
"name" : "zhi",
"lastName" : "qiao",
"job" : "enginee"
}
}
3.更新⽂档:(将上⾯新建⽂档的job字段更新⼀下)
POST /accounts/person/1/_update
{
"doc": {
"job": "software enginee"
}
}
返回结果:
#! Deprecation: [types removal] Specifying types in document update requests is deprecated, use the endpoint /{index}/_update/{id} instead.
{
"_index" : "accounts",
"_type" : "person",
"_id" : "1",
"_version" : 3,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 2,
"_primary_term" : 1
}
4.再次查看⽂档:
GET accounts/person/1
结果:
#! Deprecation: [types removal] Specifying types in document get requests is deprecated, use the /{index}/_doc/{id} endpoint instead.
{
"_index" : "accounts",
"_type" : "person",
"_id" : "1",
"_version" : 3,
"_seq_no" : 2,
"_primary_term" : 1,
"found" : true,
"_source" : {
"name" : "zhi",
"lastName" : "qiao",
"job" : "software enginee"
}
}
5.删除⽂档
DELETE accounts/person/1
结果:
#! Deprecation: [types removal] Specifying types in document index requests is deprecated, use the /{index}/_doc/{id} endpoint instead. {
"_index" : "accounts",
"_type" : "person",
"_id" : "1",
"_version" : 4,
"result" : "deleted",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 3,
mysql下载的zip版本安装步骤"_primary_term" : 1
}
6.再次查看
GET accounts/person/1
结果:
#! Deprecation: [types removal] Specifying types in document get requests is deprecated, use the /{index}/_doc/{id} endpoint instead. {
"_index" : "accounts",
"_type" : "person",
"_id" : "1",
"found" : false
}
3.Elastic Query
⾸先准备两条数据:
POST /accounts/person/1
{
"name": "zhi",
"lastName": "qiao",
"job": "enginee"
}
POST /accounts/person/2
{
"name": "zhi2",
"lastName": "qiao2",
"job": "student"
}
1.Query string:按关键字查询
GET accounts/person/_search?q=student
结果:
#! Deprecation: [types removal] Specifying types in search requests is deprecated.
{
"took" : 1557,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0925692,
"hits" : [
{
"_index" : "accounts",
"_type" : "person",
"_id" : "2",
"_score" : 1.0925692,
"_source" : {
"name" : "zhi2",
"lastName" : "qiao2",
"job" : "student"
}
}
}
}
查询不存在的关键字:
GET accounts/person/_search?q=teacher
返回结果:
#! Deprecation: [types removal] Specifying types in search requests is deprecated.
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
2.Query DSL:以JSON形式拼接查询语⾔。以httpbody发送请求
GET accounts/person/_search
{
"query": {
"term": {
"job": {
"value": "student"
}
}
}
}
结果:
#! Deprecation: [types removal] Specifying types in search requests is deprecated.
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.6931471,
"hits" : [
{
"_index" : "accounts",
"_type" : "person",
"_id" : "2",
"_score" : 0.6931471,
"_source" : {
"name" : "zhi2",
"lastName" : "qiao2",
"job" : "student"
}
}
]
}
}
3.ES整合IK中⽂分词器
Elasticsearch中,内置了很多分词器(analyzers),有standard (标准分词器)、english (英⽂分词)和chinese (中⽂分词)。其中standard 是⼀个⼀个词(汉字)切分,所以适⽤范围⼴,但是精准度低;english 对英⽂更加智能,可以识别单数负数,⼤⼩写,过滤stopwords(例如“the”这个词)
等;chinese 效果很差。
1. ⽐如使⽤默认分词器进⾏分词查看
POST /_analyze
{
"text": "我是⼀个程序员, I am CXY"
}
结果:
"tokens" : [
{
"token" : "我",
"start_offset" : 0,
"end_offset" : 1,
"type" : "<IDEOGRAPHIC>",
"position" : 0
},
{
"token" : "是",
"start_offset" : 1,
"end_offset" : 2,
"type" : "<IDEOGRAPHIC>",
"position" : 1
},
{
"token" : "⼀",
"start_offset" : 2,
"end_offset" : 3,
"type" : "<IDEOGRAPHIC>",
"position" : 2
},
{
"token" : "个",
"start_offset" : 3,
"end_offset" : 4,
"type" : "<IDEOGRAPHIC>",
"position" : 3
},
{
"token" : "程",
"start_offset" : 4,
"end_offset" : 5,
"type" : "<IDEOGRAPHIC>",
"position" : 4
},
{
"token" : "序",
"start_offset" : 5,
"end_offset" : 6,
"type" : "<IDEOGRAPHIC>",
"position" : 5
},
{
"token" : "员",
"start_offset" : 6,
"end_offset" : 7,
"type" : "<IDEOGRAPHIC>",
"position" : 6
},
{
"token" : "i",
"start_offset" : 9,
"end_offset" : 10,
"type" : "<ALPHANUM>",
"position" : 7
},
{
"token" : "am",
"start_offset" : 11,
"end_offset" : 13,
"type" : "<ALPHANUM>",
"position" : 8
},
{
"token" : "cxy",
"start_offset" : 14,
"end_offset" : 17,
"type" : "<ALPHANUM>",
"position" : 9
}
]
}
2. 整合IK中⽂分词器
1. 需要下载对应版本的插件。
2.将下载的zip包解压⾄ES_HOME/plugins/ik(ik⽬录没有的话⾃⼰新建⼀个)
3.测试分词
(1) ik_smart分析器
POST /_analyze
{
"analyzer":"ik_smart",
"text": "我是⼀个程序员"
}
结果:
{
"tokens" : [
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论