kibana学习的语法
访问:http://39.108.172.xxx:5601进入可视化管理界面
点左边Dev tools,点到哪一行就执行哪一行的
基本操作
GET /_cat/health?v // 查看运行状态
GET /_cat/nodes?v // 节点
GET /_cat/indices?v // 所有索引
PUT /goods // 新增索引
DELETE /goods
PUT /customer/_doc/1?pretty // 增加个文档,指定id
{
"name":"zhangsan",
"age":26
}
POST /customer/_doc // 增加个文档,随机id
{
"name":"lisi",
"age":25
}
GET /customer/_doc/1 // 查询得到文档,后面这个是id
PUT /customer/_doc/1 // 修改文档(所有字段都要重写一遍)
{
"name":"zhangsan",
"age":30
}
POST /customer/_doc/1/_update // 这个就是修改某一个字段了
{
"doc":{
"age":21
}
}
DELETE /customer/_doc/1 // 删除某个文档
批量操作
POST /customer/_doc/_bulk // 批量添加
{"index":{"_id":2}}
{"name":"chengyaojin"}
{"index":{"_id":3}}
{"name":"dianwei"}
POST /customer/_doc/_bulk // 批量修改和删除
{"update":{"_id":2}}
{"doc":{"name":"libai"}}
{"delete":{"_id":3}}
GET /customer/_doc/_mget // 批量获取文档
{
"ids":[1,2]
}
GET /mymay/user/_search?q=[20 TO 30] // 年龄在20-30之间的
高级查询
GET /goods/_search // 找到goods这个索引里面的数据
GET /goods/_search?q=title:xiaomi&pretty // 寻找小米
GET /goods/_search // 请求体寻找
{
"from":0,
"size":2, // 分页查询
"_source": ["title"], // 相当于select
"query":{
"match":{"title":"huawei"} //(match还有个term,term是精确匹配,match是分词查询)
}
}
一个例子
例子:
POST /goods/_doc/_bulk
{"index":{"_id":4}}
{"title":"xiaomi 6","des":"zui xin xiaomi shouji"}
{"index":{"_id":5}}
{"title":"iphone x","des":"zui xin iphone shouji"}
{"index":{"_id":6}}
{"title":"huawei v20","des":"zui xin huawei shouji"}
// 来个查询句子
GET /goods/_search
{
"query":{
"bool":{
"must":[ // 这边must可以理解为and,should=or
{"match": {"des": "shouji"}},
{"match": {"des": "xiaomi"}}
]
}
}
}
GET /goods/_search
{
"query":{
"bool":{
"should":[
{"match": {"des": "zui"}},
{"match": {"des": "xin"}},
{"match": {"des": "shouji"}}
],
"must_not":[ // 不满足这个要
{"match":{"des":"xiaomi"}}
],
"filter":{ // 添加区间查询
"range":{
"age":{
"gte":20,
"lte":30
}
}
}
}
}
}
// 先来添加个索引 ,ik类型的
PUT /tv
{
"mappings": {
"_doc":{
"properties":{
"name":{
"type":"text",
"analyzer":"ik_max_word",
"search_analyzer":"ik_max_word"
},
"desc":{
"type":"text",
"analyzer":"ik_max_word",
"search_analyzer":"ik_max_word"
}
}
}
}
}
### 我是测试ik
POST /tv/_doc/_bulk
{"index":{"_id":1}}
{"name":"小米电视2","desc":"年轻人的第一台电视"}
{"index":{"_id":2}}
{"name":"索尼安卓智能液晶电视55寸","desc":"色彩绚丽,高清画质"}
{"index":{"_id":3}}
{"name":"夏普50寸高清智能电视机","desc":"画质优美"}
##普通查询,这个是一个字一个字分开来只要有就查出来,这样是不行的
GET /tv/_search
{
"query": {
"match":{
"name":"索尼电视"
}
}
}
## ik查询,这边是检测ik怎么分词的
GET /tv/_analyze
{
"tokenizer": "ik_max_word",
"text":["索尼电视"]
}
GET /tv/_search
{
"query": {
"match_phrase": {
"name":{
"query": "索尼电视",
"slop":20 // 中间能隔多少个字
}
}
}
}
GET /product/_search
{
"query":{
"match_phrase": {
"title": {
"query":"索尼",
"slop":20
}
}
}
}
GET /product/_search // 检查索尼手机有没有添加进去
访问5601除了阿里云要开启,elasticsearch和kibana也要启动