Es删除索引数据相关命令总结

发布时间:2026/8/21 8:29:01
Es删除索引数据相关命令总结 es http请求方式es 可以通过客户端api集成操作也可以发起 http请求对集群进行操作1curl发起请求curl 使用curl -u 用户名:密码 -XPOST -H -d Content-Type: application/json http://es..... 可以命令行执行2使用RestTemplate发起http请求String url http://elastic:your_passwordyour-es-host:9200/_tasks/...; RestTemplate restTemplate new RestTemplate();但实际测试中这种url指定用户名密码不行呢 不起作用...换方法3(3) RestTemplate basicAuthHttpHeaders head new HttpHeaders(); if (!StringUtils.isEmpty(password) !StringUtils.isEmpty(username)){ head.setBasicAuth(username,password); } // // 方式2. 构建 Basic Auth 字符串 // String auth username : password; // String authHeader Basic Base64.encode(auth.getBytes(StandardCharsets.UTF_8)); // // HttpHeaders head new HttpHeaders(); // head.set(Authorization, authHeader); HttpEntityString entity new HttpEntity(head); ResponseEntityString response template.exchange( url, HttpMethod.GET, entity, String.class );这种可以执行成功es 监控类命令(1)查询指定索引的分片数curl -u 用户名:密码 -XGET http://eshost:9200/_cat/indices/myindex*?vpretty(2)查看myindex开头的索引列表curl -u 用户名:密码 -XGET http://eshost:9200/_cat/indices/myindex*?vpretty3集群健康curl -u 用户名:密码 -XGET http://eshost:9200/_cluster/health4 线程池状态拒绝率不能过高curl -u 用户名:密码 -XGET http://eshost:9200/_nodes/stats/thread_pool?filter_path**.thread_pool.rejected5磁盘使用率不能超过85%curl -u 用户名:密码 -XGET http://eshost:9200/_cat/allocation?vsdisk.percentes 删除数据命令(1)按条件删除指定索引的数据curl -u 用户名:密码 -XPOST http://eshost:9200/myindex/_delete_by_query?wait_for_completionfalseslicesautorefreshfalse -H Content-Type: application/json -d{ query: { bool: { must: [ { term: { userId: { value: } } } ] } } }注意wait_for_completionfalse说明异步执行1w的数据量秒删结果会立即返回一个任务ides集群会根据任务大小再拆分出小任务300多万数据消耗大概1分钟3亿多万条数据大概3小时当然和脚本有关脚本里有每删除1天数据等待几秒让集群恢复2根据任务id查询任务进度curl -u 用户名:密码 -XGET http://hosts:9200/_tasks/任务id(3)查询es所有的删除任务不展示明细curl -u 用户名:密码 -XGET http://eshost:9200/_tasks?actions*/delete/byquerydetailedfalse(4)任务取消curl -u 用户名:密码 -XPOST http://eshost:9200/_tasks/nC10NklZQiyi9Lohtj6a-g:45627061391/_cancel5查询es索引的文档数确认是否数据都删除curl -u 用户名:密码 -XPOST http://eshosts:9200/myindex/_count -H Content-Type: application/json -d{ query: { bool: { must: [ { term: { userId: { value: } } } ] } } }