https://www.elastic.co/guide/en/elasticsearch/reference/6.4/cat.html
https://www.elastic.co/guide/en/elasticsearch/reference/6.4/cluster.html
描述:查询集群详细信息
http://localhost:9200/_cluster/state?pretty
描述:查询集群健康信息
http://localhost:9200/_cluster/health?pretty
{
"cluster_name" : "my-es6-test",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 5,
"number_of_data_nodes" : 5,
"active_primary_shards" : 352,
"active_shards" : 583,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
描述:查询索引级别的健康状态
http://localhost:9200/_cluster/health?level=indices
描述:health是一个简洁的,一行表示了来自/_cluster/health的相同的信息。
此命令常见的用途一般有两个:
GET /_cat/health?v
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1622021030 09:23:50 my-es6-prod green 8 5 660 231 0 0 0 0 - 100.0%
curl -XGET 'localhost:9200/_cat/health?v&pretty'
curl -XGET 'localhost:9200/_cat/health?v&ts=0&pretty'
备注:它有一个 ts 选项,以禁用 timestamping(时间戳)
描述:查询集群节点磁盘信息
http://localhost:9200/_cat/allocation?v&pretty
shards disk.indices disk.used disk.avail disk.total disk.percent host ip node
117 22.3gb 33.4gb 163.2gb 196.7gb 16
116 21.4gb 49.8gb 146.8gb 196.7gb 25
116 37.2gb 63.8gb 132.8gb 196.7gb 32
117 31.7gb 43.3gb 153.3gb 196.7gb 22
117 36.8gb 47.7gb 148.9gb 196.7gb 24
描述:集群中设置是否自动创建索引
PUT _cluster/settings
{
"persistent": {
"action.auto_create_index": "false"
}
}
描述:适合节点下线,将目标结点上的shard迁移至别的节点中。迁移结束之后,取消节点禁用策略
从集群中排除节点:
PUT _cluster/settings
{
"transient": {
"cluster.routing.allocation.exclude._ip": "10.1.22.129"
}
}
取消节点禁用策略:
PUT _cluster/settings
{
"transient": {
"cluster.routing.allocation.exclude._ip": null
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/allocation-filtering.html
描述:新建索引的过程要分片,禁用了分配分片,自然也就无法新建索引。已经分配了分片只是不能再在节点之间迁移,不会影响读写。集群重启的时候关闭allocation,是为了防止节点重启时节点上的分片被重新分配,这个过程很耗费资源,而且重启是很快完成的,当集群快速重启后,其上的分片大部分是可以直接分配来用的,这样也就可以加速集群完成分片的速度,从而加速重启的速度。禁用或者不禁用allocation都不会影响业务,只是可能由于节点下线的时候由于分片重新分配导致es状态由yello到green的时间变长,从而导致重启时间边长。
开启shard迁移:
PUT /_cluster/settings
{
"transient" : {
"cluster.routing.allocation.enable" : "all"
}
}
curl -X PUT http://0.0.0.0:9200/_cluster/settings?pretty -d '{"transient":{"cluster.routing.allocation.enable":"all"}}
关闭shard迁移:
PUT /_cluster/settings
{
"transient" : {
"cluster.routing.allocation.enable" : "none"
}
}
curl -X PUT http://0.0.0.0:9200/_cluster/settings?pretty -d '{"transient": {"cluster.routing.allocation.enable": "none"}}'
描述:查看当前集群中每个结点上所执行的任务信息
查看全部执行任务:
GET _tasks
查看reinde执行任务:
GET _tasks?detailed=true&actions=*reindex
通过taskId查看某一个执行任务
GET /_tasks/rjepnVpyScSZ4KjV8iskeQ:10031170
GET /_tasks/task_id:1
通过taskId取消某一个执行任务
POST _tasks/rjepnVpyScSZ4KjV8iskeQ:10031170/_cancel
POST _tasks/task_id:1/_cancel
设置reindex速率
POST _reindex/rjepnVpyScSZ4KjV8iskeQ:10031170/_rethrottle?requests_per_second=-1
POST _reindex/task_id:1/_rethrottle?requests_per_second=-1
补充:
GET _tasks?nodes=nodeId1,nodeId2
GET _tasks?nodes=nodeId1,nodeId2&actions=cluster:*
https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html
描述:一旦我们把 number_of_shards
定下来了,我们就不可以修改了,除非把 index 删除,并重新 index 它。这是因为每个文档存储到哪一个 shard 是和 number_of_shards
这个数值有关的。一旦这个数值发生改变,那么之后寻找那个文档所在的 shard 就会不准确。
PUT /my_index
{
"settings": {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
}
单独调整副本分片
PUT /regroupmembers/_settings
{
"number_of_replicas": 1
}
注意:只能调整副本分片
描述:查询集群中节点详细信息
http://localhost:9200/_nodes?pretty
http://localhost:9200/_nodes/stats?pretty
描述:查询节点系统参数信息(堆、cpu、负载、角色、节点名)
http://localhost:9200/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
10.1.34.000 22 96 1 0.19 0.11 0.10 mdi * node-8
10.1.34.000 26 97 1 0.03 0.03 0.00 mdi - node-9
10.1.34.000 19 98 1 0.04 0.01 0.00 mdi - node-10
10.1.34.000 24 93 1 0.06 0.02 0.00 mdi - node-11
10.1.34.000 24 94 5 0.34 0.13 0.07 mdi - node-7
描述:显示自定义节点属性
https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodeattrs.html
GET /_cat/nodeattrs
http://localhost:9200/_cat/nodeattrs?v&s=name
http://localhost:9200/_cat/nodeattrs?v&h=name,pid,attr,value
name pid attr value
node-8 27678 ml.machine_memory 16725745664
node-8 27678 ml.max_open_jobs 20
node-8 27678 xpack.installed true
node-8 27678 ml.enabled true
node-9 29694 ml.machine_memory 16725745664
node-9 29694 ml.max_open_jobs 20
node-9 29694 xpack.installed true
node-9 29694 ml.enabled true
node-10 22513 ml.machine_memory 16725749760
node-10 22513 ml.max_open_jobs 20
node-10 22513 xpack.installed true
node-10 22513 ml.enabled true
node-11 23232 ml.machine_memory 16725745664
node-11 23232 ml.max_open_jobs 20
node-11 23232 xpack.installed true
node-11 23232 ml.enabled true
node-7 6514 ml.machine_memory 16725745664
node-7 6514 ml.max_open_jobs 20
node-7 6514 xpack.installed true
node-7 6514 ml.enabled true
描述:设置副本分片数
PUT /regroupmembers-21.07.14-010000/_settings
{
"number_of_replicas": 2
}
描述:查询集群中索引详细信息(docs、store、indexing、get、search、merges、fresh、flush、segments等)
http://localhost:9200/_stats
描述:查询集群中全部索引的setting设置
http://localhost:9200/_all/_settings
描述:查询集群中全部索引的索引、主副本、状态、文档数、节点等信息。shards命令详细的描述了节点包含的分片信息。它将告诉您它是一个主分片还是一个副本,和文档的数量,硬盘上占用的字节数,以及节点所在的位置。
全部索引显示:GET /_cat/shards?v
index shard prirep state docs store ip node
sphinx-doctor-21.02.05-095258 0 p STARTED 114155 147.8mb 10.1.34.231 node-10
sphinx-doctor-21.02.05-095258 0 r STARTED 114155 147.8mb 10.1.34.134 node-11
sphinx-doctor-21.02.05-095258 0 r STARTED 114155 147.8mb 10.1.34.104 node-7
sphinx-diseasehospitalfaculty-20.12.21-153930 0 p STARTED 21600 13.1mb 10.1.34.231 node-10
sphinx-diseasehospitalfaculty-20.12.21-153930 0 r STARTED 21600 13.1mb 10.1.34.104 node-7
drug-21.03.15-102016 0 r STARTED 202138 5.3gb 10.1.34.134 node-11
指定索引显示:GET _cat/shards/health-21.03.23-010000?v
index shard prirep state docs store ip node
health-21.03.23-010000 0 p STARTED 628921 226.3mb 10.3.19.148 data-4
health-21.03.23-010000 0 r STARTED 628921 194.9mb 10.3.19.35 data-3
health-21.03.23-010000 0 r STARTED 628921 197.6mb 10.3.18.136 data-6
描述:查询某一个索引的分段信息
GET /test/_segments
描述:查询全部索引的健康信息
http://localhost:9200/_cat/indices?v
curl -XGET "http://localhost:9200/_cat/indices?v"
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open articleid -pj_38W2Sru791jdcMOvAA 5 1 7000 0 50.2mb 25.1mb
green open drug-21.01.19-125644 QLWGEVsXTiSvyIrenev7zQ 1 1 194592 1295 10.6gb 5.3gb
green open sphinx-hospitalfaculty-20.07.07-103451 FmFE5diwQ7OFDoSeasxZaQ 1 1 107615 30593 329.2mb 164.6mb
green open sphinx-doctor-21.01.08-163132 EwjRPpj4S2Gvmg6ZUMrfBA 1 1 252521 3089 520.1mb 260mb
描述:对冷索引进行close处理
#关闭不需要的索引,减少内存占用
curl -XPOST "http://localhost:9200/index_name/_close"
描述:查询索引时,返回doc版本号
GET sphinx-disease/_search
{
"query": {
"match_all": {}
},
"version": true
}
描述:查询某一个索引在集群节点中的分布信息
http://localhost:9200/sphinx-disease/_search_shards
{
"nodes" : {
"dVzWLgCbRKy-l5a8bwNxAA" : {
"name" : "node-9",
"ephemeral_id" : "jesbPIilQhWorkEBtWXBtw",
"transport_address" : "10.1.34.45:9300",
"attributes" : {
"ml.machine_memory" : "16725745664",
"ml.max_open_jobs" : "20",
"xpack.installed" : "true",
"ml.enabled" : "true"
}
},
"LatycNilQl2Kj5phCqFQhA" : {
"name" : "node-8",
"ephemeral_id" : "LEfk0SEOQnChRaziv_gIWQ",
"transport_address" : "10.1.34.146:9300",
"attributes" : {
"ml.machine_memory" : "16725745664",
"ml.max_open_jobs" : "20",
"xpack.installed" : "true",
"ml.enabled" : "true"
}
}
},
"indices" : {
"sphinx-disease-20.05.18-143503" : {
"aliases" : [
"sphinx-disease"
]
}
},
"shards" : [
[
{
"state" : "STARTED",
"primary" : true,
"node" : "LatycNilQl2Kj5phCqFQhA",
"relocating_node" : null,
"shard" : 0,
"index" : "sphinx-disease-20.05.18-143503",
"allocation_id" : {
"id" : "XENT7DXCTBCwFfmMEqhBDw"
}
},
{
"state" : "STARTED",
"primary" : false,
"node" : "dVzWLgCbRKy-l5a8bwNxAA",
"relocating_node" : null,
"shard" : 0,
"index" : "sphinx-disease-20.05.18-143503",
"allocation_id" : {
"id" : "9mJBFw0ISsuVTNySP3La-w"
}
}
]
]
}
描述:查看某个索引所有segment的memory占用情况
GET _cat/segments/sphinx-doctor
sphinx-doctor-21.01.29-104911 0 p 10.1.22.129 _kq 746 73913 169 86.5mb 163327 true true 7.7.0 false
sphinx-doctor-21.01.29-104911 0 p 10.1.22.129 _1ql 2253 3811 8 4.3mb 27204 true true 7.7.0 true
sphinx-doctor-21.01.29-104911 0 p 10.1.22.129 _1s9 2313 3257 4 4.1mb 25928 true true 7.7.0 true
sphinx-doctor-21.01.29-104911 0 p 10.1.22.129 _1sj 2323 154612 77 163.5mb 341195 true true 7.7.0 false
sphinx-doctor-21.01.29-104911 0 p 10.1.22.129 _21p 2653 2934 0 3.7mb 25627 true true 7.7.0 true
sphinx-doctor-21.01.29-104911 0 p 10.1.22.129 _229 2673 18941 7 22.9mb 74816 true true 7.7.0 true
查看索引segment指定的信息:GET /_cat/segments/sphinx-doctor?v&h=index,shard,segment,size,size.segment
index shard segment size
sphinx-doctor-21.02.19-104606 0 _84 23.5mb
sphinx-doctor-21.02.19-104606 0 _fo 50.3mb
sphinx-doctor-21.02.19-104606 0 _66b 5mb
sphinx-doctor-21.02.19-104606 0 _6d6 2.7mb
sphinx-doctor-21.02.19-104606 0 _6e4 5.3mb
sphinx-doctor-21.02.19-104606 0 _6ih 465kb
sphinx-doctor-21.02.19-104606 0 _6ij 25.2kb
sphinx-doctor-21.02.19-104606 0 _6im 26.1kb
查看node上所有segment占用的memory总和:GET /_cat/nodes?v&h=name,port,sm
name port sm
node-10 9300 72.9mb
node-11 9300 44.7mb
node-8 9300 146.6mb
node-7 9300 134.4mb
node-9 9300 105.4mb
描述:执行某一个索引的段合并
POST sphinx-doctor/_forcemerge?only_expunge_deletes=true
描述:自定义索引在结点之间迁移
POST /_cluster/reroute
{
"commands" : [ {
"move" :
{
"index" : "suggest_article",
"shard" : 3,
"from_node" : "node-8",
"to_node" : "node-6"
}
}
]
}
官网地址:
https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-reroute.html
描述:索引的增删改查操作
删除
##删除某个索引:
curl -XDELETE 'http://localhost:9200/sphinx-doctor'
##删除索引下的全部数据:
POST sphinx-doctor/_delete_by_query?refresh
{ "query": { "match_all": {} } }
##通过ID删除某一条数据:
DELETE http://localhost:9200/flowindex_20180918-10:15:25/flow/5785743737
新增
##索引插入一条数据:
PUT test_doctor/_doc/1
{
"name1":"樊万虎",
"name2":"樊万虎",
"nums":"20200915,20200922,20200929"
}
更新
##更新一条doc的某一个字段更新:
POST sphinx-diseasedoctor/_update_by_query
{
"query": {
"match": {
"category.keyword": ""
}
},
"script": {
"source": """ ctx._source['category'] = "None" """
}
}
POST sphinx-doctor/_doc/4861/_update
{
"doc" : {
"name" : "齐美”
}
}
POST sphinx-doctor/_doc/1134/_update
{
"script": {
"source": "ctx._source.price = 300"
}
}
POST sphinx-doctor/_doc/1134/_update
{
"script": {
"source": "ctx._source.price = params.value",
"lang": "painless",
"params": {
"value": 301
}
}
}
查询
##指定查询主分片
GET sphinx-doctor/_search?preference=_primary
##指定查询副本分片
GET sphinx-doctor/_search?preference=replicas
描述:setting&mapping操作
PUT /test_doctor
{
"settings":{
"number_of_shards":1,
"analysis":{
"analyzer":{
"index_ansj_analyzer":{
"type":"custom",
"tokenizer":"index_ansj",
"filter":[
"my_synonym",
"asciifolding"
]
},
"comma":{
"type":"pattern",
"pattern":","
},
"shingle_analyzer":{
"type":"custom",
"tokenizer":"standard",
"filter":[
"lowercase",
"shingle_filter"
]
}
},
"filter":{
"my_synonym":{
"type":"synonym",
"synonyms_path":"analysis/synonym.txt"
},
"shingle_filter":{
"type":"shingle",
"min_shingle_size":2,
"max_shingle_size":2,
"output_unigrams":false
}
}
}
}
}
查看Setting:
GET test_doctor/_settings
http://localhost:9200/account/_settings?pretty
http://localhost:9200/sphinx-hospitalfaculty/_settings?preserve_existing=true
PUT /test_doctor/_mapping/_doc
{
"_doc": {
"properties": {
"name1": {
"type": "text",
"analyzer": "index_ansj_analyzer"
},
"name2": {
"type": "text"
},
"nums": {
"type": "text",
"analyzer": "comma"
}
}
}
}
查看Mapping:
GET test_doctor/_mapping
http://localhost:9200/account/_mappings?pretty
描述:新旧索引之间重新索引数据
POST _reindex
{
"source": {
"index": "sphinx-doctor_20190515-19:53:24" #旧索引
"type": "_doc",
"size": 5000, #默认是1000
"query": {
"term": {
"user": "kimchy"
}
}
},
"dest": {
"index": "sphinx-doctor_20190614-16:15:07" #新索引
}
}
补充:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html
描述:索引别名操作
POST /_aliases
{
"actions":[
{
"remove":{
"index":"test1",
"alias":"alias1"
}
},
{
"add":{
"index":"test1",
"alias":"alias2"
}
}
]
}
#切换别名
POST /_aliases
{
"actions": [
{
"remove": {
"index": "regroupmembers-20.11.12-151612",
"alias": "regroupmembers"
}
},
{
"add": {
"index": "regroupmembers-20.11.12-171408",
"alias": "regroupmembers"
}
}
]
}
#添加别名
POST _aliases
{
"actions": [
{
"add": {
"index": "sphinx-diseasehospital-20.11.30-161133",
"alias": "sphinx-diseasehospital"
}
}
]
}
#删除别名
POST /_aliases
{
"actions": [{
"remove": {
"index": "sphinx-doctor-19.07.12-144934",
"alias": "sphinx-doctor"
}
}]
}
描述:批量操作
POST _bulk
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_id" : "2" } }
{ "create" : { "_index" : "test", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
描述:查看某一个索引的详细信息(文档数、refresh、flush、query等)
GET /indexname/_stats?level=shards
描述:分词器分词结果展示
POST _analyze
{
"analyzer":"query_ansj”,
"text":"十堰市红十字医院”
}
#对索引指定字段的分词器进行分词结果查询
POST index_name/_analyze
{
"field":"firtname", #要进行分析的索引中的字段
"text":"ni cai" #要进行分析的文本
}
例如:
POST http:///localhost:9200/doctorindex_20170830-17:00:35/_analyze
{
"field": "drName.drNgramName",
"text": "成雄超"
}
#自定义分词器进行测试
POST _analyze
{
"tokenizer":"standard", #指定的分词器
"filter":["lowercase"], #对分析后的词最后进行小写转换
"text":"hello world" #要进行分析的文本
}
例如:
POST http://localhost:9200/_analyze
{
"char_filter": [],
"tokenizer": "standard",
"filter": [
"stop",
"lowercase",
"stemmer"
],
"text": "Eating an apple a day keeps do"
}
#查看所有字段的分词结果
http://ip:port/indexName/indexType/id/_termvectors?fields=*
例如:http://localhost:9200/sphinx-diseasehospital/diseasehospital/5617268366/_termvectors?fields=*
#查看某一字段的分词结果
http://ip:port/indexName/indexType/id/_termvectors?fields=fieldName
例如:
http://localhost:9200/sphinx-disease/_doc/2849/_termvectors?fields=name
#验证分词器的实现状:
http://127.0.0.1:9200/sphinx-doctorinfo/_analyze?analyzer=comma&text=2,3,4,5,100-100
描述:展示分词的Tf/Idf详情
GET sphinx-doctor/_validate/query?explain
{
"query": {
"bool": {
"should": {
"match": {
"hospitalname": {
"query": "滨州市"
}
}
}
}
}
}
结果:
{
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"valid" : true,
"explanations" : [
{
"index" : "sphinx-doctor-19.07.12-144934",
"valid" : true,
"explanation" : "(hospitalname:滨州市 hospitalname:滨州 hospitalname:滨 hospitalname:州市 hospitalname:州 hospitalname:市)"
}
]
}
词频/反向文档频
POST sphinx-disease/_search?format=yaml
{
"from": 0,
"size": 10,
"explain": true,
"query": {}
}
JSON 形式的 explain 描述是难以阅读的, 但是转成 YAML 会好很多,只需要在参数中加上 format=yaml
描述:修改索引返回的最大结果窗口
PUT:http://127.0.0.1:9200/sphinx-hospitalfaculty/_settings?preserve_existing=true
{
"max_result_window": "2000000000"
}
响应:
{
"acknowledged": true
}
描述:查询Es中scope字段为null值的数据
POST regroupmembers/_search
{
"query" : {
"bool": {
"must_not": {
"exists" : { "field" : "scope" }
}
}
}
}
描述:设置文档刷新频率
PUT /retopic-21.07.07-012543/_settings
{
"refresh_interval": "10s"
}
https://www.kancloud.cn/apachecn/elasticsearch-doc-zh/1945150
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。