Kibana 是为 Elasticsearch设计的开源分析和可视化平台。你可以使用 Kibana 来搜索,查看存储在 Elasticsearch 索引中的数据并与之交互。你可以很容易实现高级的数据分析和可视化,以图表的形式展现出来。
直接下载对应平台的版本解压就可以,我的版本是Window kibana7.7.1,下装地址
config/kibana.yml 建议设置监听端口号、es地址、索引名
config/kibana.yml 建议配置成中文
点击kibana.bat启动
浏览器输入http://localhost:5601即可打开
打开控制台依次创建ES的index、settings、mapping
GET /test_v1/_settings
PUT /test_v1
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"analyzer": {
"icu_analyzer": {
"tokenizer": "icu_tokenizer"
}
}
}
}
}
GET /test_v1/_mapping
PUT /test_v1/_mapping
{
"properties": {
"itemId": {
"type": "integer"
},
"categoryIds": {
"type": "text",
"analyzer": "whitespace",
"fielddata": true
},
"tags": {
"type": "text",
"analyzer": "whitespace",
"fielddata": true
},
"title": {
"type": "text",
"analyzer": "icu_analyzer"
},
"summary": {
"type": "text"
},
"marketPrice": {
"type": "double"
},
"marketPriceTxt": {
"type": "keyword"
},
"newFlag": {
"type": "integer"
},
"attrsList": {
"type": "nested",
"properties": {
"attrKey": {
"type": "keyword"
},
"attrValue": {
"type": "text",
"analyzer": "whitespace"
}
}
},
"gmtCreate": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
}
POST /_aliases
{
"actions": [
{ "add": { "index": "test_v1", "alias": "test" }}
]
}
特别说明
1.title与summary都采用了分词,但是summary没有指定,实际搜索时分词结果时不一样的
2.attrsList采用的是nested,可以使用嵌套搜索(例如身高/颜色/尺码等等)
3.tags指定了空格分词,使用场景如标签/特性
4.添加别名时还可以设置其他属性如:“is_write_index”: true。别名可以和索引名有同样的功能,而且更强大。常见使用场景
/**
*由于Elasticsearch底层使用了lucene的原因,不支持对mapping的修改,可使用索引重建的方式,步骤如下
*/
//1,依照索引test_v1创建一份正确的索引test_v2
//2,使用reindex api将旧索引数据导入新索引,或者也可以采用把数据直接导入test_v2
//索引重建后可使用reindex命令迁移数据,如将test_v1数据迁移至test_v2请求如下:
POST _reindex
{
"source": {
"index": "test_v1",
"type": "item"
},
"dest": {
"index": "test_v2",
"type": "item"
}
}
//3,将旧索引别名迁移到新索引请求
POST /_aliases
{
"actions" : [
{ "remove" : { "index" : "test_v1", "alias" : "test" } },
{ "add" : { "index" : "test_v2", "alias" : "test" } }
]
}
//4,删除旧索引,添加或迁移别名后删除旧索引:
DELETE /test_v1
5.其他语法
#清空数据
POST flmall_item_th_v1/_delete_by_query
{
"query": {
"match_all": {
}
}
}
#分词
GET /test/_analyze
{
"analyzer": "icu_analyzer",
"text": "กระเป๋าสะพายสายกว้างแบบเข้าช"
}
#查询
GET test/_search
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": [
{
"term": {
"newFlag": {
"value": 1,
"boost": 1
}
}
},
{
"match": {
"categoryIds": {
"query": "12",
"operator": "OR",
"prefix_length": 0,
"max_expansions": 50,
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 1
}
}
},
{
"nested": {
"query": {
"term": {
"attrsList.attrKey": {
"value": "101",
"boost": 1
}
}
},
"path": "attrsList",
"ignore_unmapped": false,
"score_mode": "sum",
"boost": 1
}
}
],
"must_not": [
{
"term": {
"sid": {
"value": "tigQqwdt",
"boost": 1
}
}
},
{
"nested": {
"query": {
"term": {
"attrsList.attrValue": {
"value": "134",
"boost": 1
}
}
},
"path": "attrsList",
"ignore_unmapped": false,
"score_mode": "sum",
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"_source": {
"includes": [
"title",
"sid",
"itemId"
],
"excludes": []
},
"sort": [
{
"_script": {
"script": {
"source": "doc['itemId'].value + params.randomSort",
"lang": "painless",
"params": {
"randomSort": 100
}
},
"type": "number",
"order": "desc"
}
}
]
}
Kibana 可视化ElasticSearch数据展示分析 参考文档