windows 环境下搭建electricSearch+kibana
1.ES7.3.2 + kibana + ik-smart
百度网盘下载地址:https://pan.baidu.com/s/1eCKTYoosXl8NfX37EwjyWA
提取码:ibcf
上面提取码错误请用下面 2021-05-15修改
链接: https://pan.baidu.com/s/1oxwPbyk37P_V8hitVuwCbg 提取码: x958 复制这段内容后打开百度网盘手机App,操作更方便哦
kibana 操作文档
GET _search { "query": { "match_all": {} } } ### 查看集群健康信息 GET /_cat/health?v ### 帮助 GET /_cat/health?help ### 查看集群中节点信息 GET /_cat/nodes?v ### 查看集群中索引信息 GET /_cat/indices?v ### 精简信息 GET /_cat/indices?v&h=health,status,index ### 创建索引 PUT /baizhi ### 删除索引 DELETE /baizhi ### 创建类型mapping POST /baizhi/user { "user": { "properties": { "id": { "type": "text" }, "name": { "type": "text" }, "age": { "type": "integer" }, "created": { "type": "date", "format": "strict_date_optional_time || epoch_millis" } } } } ### 查看类型mapping GET /baizhi/_mapping ### 新增单个文档 PUT /baizhi/user/1 { "name":"zs", "title":"张三", "age":18, "created":"2018-12-25" } ### 查询所有文档 GET /zpark/user/_search ### 指定id查询单个文档 GET /baizhi/user/1 ### 修改单个文档 PUT /baizhi/user/1 { "name": "lxs", "title": "李小四" } ### 删除单个文档 DELETE /baizhi/user/1 ### 批量新增 POST /baizhi/user/_bulk {"index":{}} {"name":"ww","title":"王五","age":18,"created":"2018-12-27"} {"index":{}} {"name":"zl","title":"赵六","age":25,"created":"2018-12-27"} ### 批量删除 POST /baizhi/user/_bulk {"update":{"_id":"K38E728BJ1QbWBSobMEC"}} {"doc":{"title":"王小五"}} {"delete":{"_id":"LH8E728BJ1QbWBSobMEC"}} ##############进阶############## ########### 查询(Query) # 批量插入测试数据 POST /zpark/user/_bulk {"index":{"_id":1}} {"name":"zs","realname":"张三","age":18,"birthday":"2018-12-27","salary":1000.0,"address":"北京市昌平区沙阳路55号"} {"index":{"_id":2}} {"name":"ls","realname":"李四","age":20,"birthday":"2017-10-20","salary":5000.0,"address":"北京市朝阳区三里屯街道21号"} {"index":{"_id":3}} {"name":"ww","realname":"王五","age":25,"birthday":"2016-03-15","salary":4300.0,"address":"北京市海淀区中关村大街新中关商城2楼511室"} {"index":{"_id":4}} {"name":"zl","realname":"赵六","age":20,"birthday":"2003-04-19","salary":12300.0,"address":"北京市海淀区中关村软件园9号楼211室"} {"index":{"_id":5}} {"name":"tq","realname":"田七","age":35,"birthday":"2001-08-11","salary":1403.0,"address":"北京市海淀区西二旗地铁辉煌国际大厦负一楼"} ### 查看所有并按照年龄降序排列 GET /zpark/user/_search { "query": { "match_all": {} }, "sort": { "age": "desc" } } ### 查询第2页的用户(每页显示2条) GET /zpark/user/_search { "query": { "match_all": {} }, "sort": { "age": "desc" }, "from": 2, "size": 2 } ### 查询address在海淀区的所有用户,并高亮 GET /zpark/user/_search { "query": { "match": { "address": { "analyzer": "ik_max_word", "query": "海淀区" } } }, "highlight": { "fields": { "address": {} } } } ### 设置索引分词器 PUT /zpark { "settings" : { "index" : { "analysis.analyzer.default.type": "ik_smart" } } } ### 查询name是zs关键字的用户 GET /zpark/user/_search { "query":{ "term": { "name": { "value": "zs" } } } } ### 查询年龄在20~30岁之间的用户 GET /zpark/user/_search { "query": { "range": { "age": { "gte": 20, "lte": 30 } } } } ### 查询真实姓名以李开头的用户 GET /zpark/user/_search { "query": { "prefix": { "realname": { "value": "李" } } } } ### 查询名字以s结尾的用户 GET /zpark/user/_search { "query": { "wildcard": { "name": { "value": "*s" } } } } ### 查询id为1,2,3的用户 GET /zpark/user/_search { "query": { "ids": { "values": [1,2,3] } } } ### 模糊查询realname中包含张关键字的用户 GET /zpark/user/_search { "query": { "wildcard": { "realname": {"value": "*张*"} } } } ### 查询age在15-30岁之间并且name必须通配z* GET /zpark/user/_search { "query": { "bool": { "must": [ { "range": { "age": { "gte": 15, "lte": 30 } } }, { "wildcard": { "name": { "value": "z*" } } } ], "must_not": [ { "regexp": { "name": ".*s" } } ] } } } ############# 过滤器(Filter) ### 其实准确来说,ES中的查询操作分为2种:查询(query)和过滤(filter)。查询即是之前提到的query查询,它(查询)默认会计算每个返回文档的得分,然后根据得分排序。而过滤(filter)只会筛选出符合的文档,并不计算得分,且它可以缓存文档。所以,单从性能考虑,过滤比查询更快。 ### 换句话说,过滤适合在大范围筛选数据,而查询则适合精确匹配数据。一般应用时,应先使用过滤操作过滤数据,然后使用查询匹配数据。 ### 过滤器使用 ranage filter GET /zpark/user/_search { "query":{ "bool": { "must": [ {"match_all": {}} ], "filter": { "range": { "age": { "gte": 25 } } } } } } ### term、terms Filter term、terms的含义与查询时一致。term用于精确匹配、terms用于多词条匹配 GET /zpark/user/_search { "query":{ "bool": { "must": [ {"match_all": {}} ], "filter": { "terms": { "name": [ "zs", "ls" ] } } } } } ### exists filter exists过滤指定字段没有值的文档 GET /zpark/user/_search { "query": { "bool": { "must": [ { "match_all": {} } ], "filter": { "exists": { "field": "salary" } } } }, "sort": [ { "_id": { "order": "asc" } } ] } ### ids filter 需要过滤出若干指定_id的文档,可使用标识符过滤器(ids) GET /zpark/user/_search { "query": { "bool": { "must": [ { "match": { "address": "昌平区" } } ], "filter": { "ids": { "values": [ 1, 2, 3 ] } } } },"highlight": { "fields": { "address": {} } } } #############聚合(Aggregations) ### 度量(metric)聚合 POST /zpark/user/_search { "aggs": { "age_avg": { "avg": {"field": "age"} } } } ### 先过滤,再进行统计,如: POST /zpark/user/_search { "query": { "ids": { "values":[1,2,3] } }, "aggs": { "age_avg": { "avg": {"field": "age"} } } } ### 最大值查询。如:查询员工的最高工资 POST /zpark/user/_search { "aggs": { "max_salary": { "max": { "field": "salary" } } } } ### 统计查询,一次性统计出某个字段上的常用统计值 POST /zpark/user/_search { "aggs": { "max_salary": { "stats": { "field": "salary" } } } } ### 桶(bucketing)聚合 自定义区间范围的聚合,我们可以自己手动地划分区间,ES会根据划分出来的区间将数据分配不同的区间上去。 ### 统计0-20岁,20-35岁,35~60岁用户人数 POST /zpark/user/_search { "aggs": { "age_ranges": { "range": { "field": "age", "ranges": [ { "from": 0, "to": 20 }, { "from": 20, "to": 35 }, { "from": 35, "to": 60 } ] } } } } ### 根据年龄分组,统计相同年龄的用户 POST /zpark/user/_search { "aggs": { "age_counts":{ "terms": { "field": "age", "size": 2 } } } } ### 时间区间聚合专门针对date类型的字段,它与Range Aggregation的主要区别是其可以使用时间运算表达式。 ### now+10y:表示从现在开始的第10年。 ### now+10M:表示从现在开始的第10个月。 ### 1990-01-10||+20y:表示从1990-01-01开始后的第20年,即2010-01-01。 ### now/y:表示在年位上做舍入运算。 ### 统计生日在2018年、2017年、2016年的用户 POST /zpark/user/_search { "aggs": { "date_counts": { "date_range": { "field": "birthday", "format": "yyyy-MM-dd", "ranges": [ { "from": "now/y", "to": "now" }, { "from": "now/y-1y", "to":"now/y" }, { "from": "now/y-2y", "to":"now/y-1y" } ] } } } } ### 嵌套使用 ### 聚合操作是可以嵌套使用的。通过嵌套,可以使得metric类型的聚合操作作用在每一bucket上。我们可以使用ES的嵌套聚合操作来完成稍微复杂一点的统计功能。 ### 如:统计每年中用户的最高工资 POST /zpark/user/_search { "aggs": { "date_histogram": { "date_histogram": { "field": "birthday", "interval": "year", "format": "yyyy-MM-dd" }, "aggs": { "salary_max": { "max": { "field": "salary" } } } } } }
⎛⎝官萧何⎠⎞一只快乐的爪哇程序猿;邮箱:1570608034@qq.com