总结一下最近频繁使用的api,以备不时之需,使用的是kibana可视化工具。
![image]()
查看索引中的数据
1 2 3 4
| GET 20220918_weibo/_search { "size":5 }
|
根据id查看某个文档
1
| GET yqms_20220918_weibo/_doc/20220918_1_06a8fe74714cac2554a704e3f6022f47
|
查看索引数据量
1
| GET /20220918_weibo/_count
|
Tips:支持*通配符
查看分词器
1 2 3 4 5
| GET 20220918_weibo/_analyze { "field": "title", "text": "志胜说自己是红绿色盲" }
|
索引的分片信息
1
| GET _cat/shards/20220116_weibo?v
|
v会增加表头
批量改副本数
复制分片会让你的数据更安全,查询更快,但会影响你入库的速度,所以当数据发生大量拥堵时,可以临时调整分片数,加快入库速度。
1 2 3 4 5 6
| PUT 20220926*/_settings { "index" : { "number_of_replicas" : 0 } }
|
查看索引别名是否存在
1
| HEAD /_alias/20220918_weibo
|
添加索引别名
1 2 3 4 5 6 7 8 9 10 11
| POST _aliases { "actions": [ { "add": { "index": "old_20220919_weibo", "alias": "new_20220919_weibo" } } ] }
|
删除索引别名
1 2 3 4 5 6 7 8 9 10 11
| POST /_aliases { "actions": [ { "remove": { "index": "old_20220919_weibo", "alias": "new_20220919_weibo" } } ] }
|
query string
这个api支持AND、OR、 NOT 、”” (记得大写),另外,还可以指定type类型:best_fields(默认)、phrase
官方文档
批量更新文档
1 2 3 4 5 6 7 8 9
| POST /20220918_*/_update_by_query { "query": { "match_all": {} }, "script": { "source": "ctx._source.distinguish_type = 1" } }
|
根据id删除
1
| DELETE /20220918_weibo/_doc/13l3G3kBX4ydNSzBVQtb
|
批量删除指定文档
1 2 3 4 5 6
| POST 20220918_weibo/_delete_by_query?wait_for_completion=false&scroll_size=1000&conflicts=proceed { "query": { "match_all":{} } }
|
重建索引
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| { "source": { "index": "old_20220910_weibo", "size":5000 }, "dest": { "index": "new_20220910_weibo", "op_type": "create" }, "conflicts": "proceed", "script": { "source":""" def publish_time; if(ctx._source.ctime !=null ){ publish_time = ctx._source.ctime * 1000L; } """ } }
|
删除索引
筛选指定执行中的任务
1
| GET _tasks?detailed=true&actions=*reindex
|
根据任务id查看任务
1
| GET _tasks/9eOsi8WJRIyQNnLr5ZxndA:368975752
|
取消任务
1
| POST _tasks/9eOsi8WJRIyQNnLr5ZxndA:367774670/_cancel
|
批量更新
1 2 3 4 5 6 7 8 9
| POST /20220918_weibo/_update_by_query { "query": { "match_all": {} }, "script": { "source": "ctx._source.distinguish_type = 1" } }
|
删除快照
1
| DELETE _snapshot/{repository}/{snapshot}
|
es集群状态
查看当前es正在运行的线程
1
| GET /_cat/thread_pool/?v&h=id,name,active,rejected,completed,size,type&pretty&s=type
|
当前活跃的线程
查询节点状态
查看分片失败的原因
1
| GET /_cluster/allocation/explain?pretty
|
尝试重新分配失败的分片
1
| POST /_cluster/reroute?retry_failed=true
|
清除缓存