安装和配置
http://lxw1234.com/archives/2018/08/926.htm 单机es集群
配置
- cluster.name: chenshun 集群名字
- node.name: node-chenshun-1 集群节点描述
- path.data: /Users/chenshun/es/es6/elasticsearch-6.6.2.1/data 节点存储数据
- path.logs: /Users/chenshun/es/es6/elasticsearch-6.6.2.1/logs 日志
- http.port: 9201 对外暴露的http端口
- transport.tcp.port: 9301 内部通讯的端口
- discovery.zen.ping.unicast.hosts: [“127.0.0.1:9301”, “127.0.0.1:9302”,”127.0.0.1:9303”] 启动集群
5.3.0 集群安装
公共ES集群 192.168.250.28 , 192.168.250.29 , 192.168.250.30
基础接口
- GET _cat/health?v 查看集群健康状况
- GET _cat/nodes?v 节点的情况
- GET _cat/indices 列出所有的索引
- yellow open collect-info YJWSuafxT1CwjjF3DUWjDQ 5 1 19 0 211.7kb 211.7kb
- yellow open book jZ0o9KqaRbG6Lmabgba2vw 5 1 3 0 22.1kb 22.1kb
- yellow open .kibana SqhURfBAQiWstTKDNPyhZg 1 1 4 1 21.2kb 21.2kb
- yellow open user-info-20190524 ttnZDn18R6mpzk4rvcehJQ 5 1 7 0 37.8kb 37.8kb
GET /collect-info/_search 查询一个具体的索引,匹配所有的document{"query": {"match_all": {}},"from": 2,//从第几个开始,默认是0"size": 1//指定搜索的数据量}搜索文档并排序GET /collect-info/_search{"query": {"match_all": {}},"from": 2,"size": 2,"sort": [{"duration": { //指定排序的field"order": “asc” 递增还是递减}}]}搜索指定字段GET /collect-info/_search{"query": {"match_all": {}},"_source": ["traceId","date”] //通过这里去指定,_source仅包含这些字段}
精确查询
GET /collect-info/_search{"query": {"match": {"traceId": "76c08c9edf6b4559a82f14061035dac6"}}}使用match指定具体的查询字段Match 精确匹配使用Match_all 匹配全部Match_phrase 短语匹配Match_phrase_prefix 短语前缀匹配multi_match 多个匹配
聚合
GET /collect-info/_search{"size": 0,"aggs": {"total": { //指定本次聚合的名字"terms": {"field": “type.keyword” 使用的key}}}}
时间日期聚合
GET /collect-info/_search{"size": 0,"aggs": {"test_timer": {"date_histogram": {"field": "date","interval": "day"}}}}
时间区域聚合
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html 2个日期做聚合GET /collect-info/_search{"size": 0,"aggs": {"range": {"date_range": {"field": "date","ranges": [{"from": "now-5d/d","to": "now"}]}}}}几天前到现在做一次聚合操作
