项目问题排查中的ES常用命令
查看/索引名称/的数据结构
curl ip:9200/indices/_mapping?pretty
查看所有索引
curl ip:9200/_cat/indices?v
删除索引
删除指定索引
curl -XDELETE ip:9200/system-log-2019.05
其中system-log-2019.05为索引全称删除多个索引
curl -XDELETE ip:9200/system-log-2019.05,system-log-2019.05删除所有索引
curl -XDELETE ip:9200/_all
或者
curl -XDELETE ip:9200/*
新增索引
curl -XPUT <http://ip:9200/test-index
模板
curl -XDELETE localhost:9200/_template/template_1
curl -XGET localhost:9200/_template/template_1
修复索引字段上限
curl -XPUT [http://ip:9200/出问题的那个索引名称/_settings](http://ip:9200/%E5%87%BA%E9%97%AE%E9%A2%98%E7%9A%84%E9%82%A3%E4%B8%AA%E7%B4%A2%E5%BC%95%E5%90%8D%E7%A7%B0/_settings) -d '{"index.mapping.total_fields.limit": 2000}' 复制代码
更新模板(!!覆盖式更新)
curl -XPUT <http://ip:9200/_template/ctu->* -d '{"template":"ctu-*","settings":{"index.mapping.total_fields.limit":2000}}' 复制代码
ES动态模板类型推断### 查看/索引名称/的数据结构
curl 10.1.2.48:9200/indices/_mapping?pretty curl 10.2.1.106:9200/case-manager-center/_mapping?pretty curl 10.1.2.48:9200/_cat/indices?v 复制代码
删除索引
删除指定索引
curl -XDELETE 192.168.1.4:9200/system-log-2019.05
其中system-log-2019.05为索引全称删除多个索引
curl -XDELETE 192.168.1.4:9200/system-log-2019.05,system-log-2019.05删除所有索引
curl -XDELETE 192.168.1.4:9200/_all
或者
curl -XDELETE 192.168.1.4:9200/*
新增索引
curl -XPUT http://10.1.2.48:9200/case-manager-center
模板
curl -XDELETE localhost:9200/_template/template_1
curl -XGET localhost:9200/_template/template_1
修复索引字段上限
curl -XPUT http://ip:9200/出问题的那个索引名称/_settings -d '{"index.mapping.total_fields.limit": 2000}'
更新模板(!!覆盖式更新)
curl -XPUT http://ip:9200/_template/ctu-* -d '{"template":"ctu-*","settings":{"index.mapping.total_fields.limit":2000}}'
聚合查询
{ "from": 0, "size": 10000, "query": { "bool": { "must": [ { "range": { "requestTime": { "from": "2021-01-22 00:00:00", "to": "2021-01-22 23:59:59", "include_lower": true, "include_upper": true, "time_zone": "+08:00", "format": "yyyy-MM-dd HH:mm:ss", "boost": 1.0 } } }, { "terms": { "appId": [ "1" ], "boost": 1.0 } } ], "disable_coord": false, "adjust_pure_negative": true, "boost": 1.0 } }, "sort": [ { "requestTime": { "order": "desc" } } ], "aggregations": { "riskRuleIds": { "terms": { "field": "reviewRuleIds", "size": 10, "min_doc_count": 1, "shard_min_doc_count": 0, "show_term_doc_count_error": false, "order": [ { "_count": "desc" }, { "_term": "asc" } ] } } } }
作者:ShowMaker
链接:https://juejin.cn/post/7022812428383715365