ES常用命令-------------随笔

来源:互联网 发布:淘宝云标签网址 编辑:程序博客网 时间:2024/05/16 18:03
【shrink】要求如下1首先,它使用与源索引相同的定义创建一个新的目标索引,但是比原索引的主碎片少。2然后将源索引中的硬链接段与目标索引关联起来。(如果文件系统不支持硬链接,那么所有的片段都被复制到新的索引中,这是一个更耗时的过程。)3最后,它恢复了目标索引,就像它是一个刚刚重新打开的封闭索引。***为了缩小索引,索引必须被标记为只读,索引中每个shard的(主或副本)副本必须迁移到相同的节点并具有健康绿色强制将每个shard的副本迁移到具有名称收缩的节点。【"index.routing.allocation.require._name": "node-1"】将索引设置成 只读模式【"index.blocks.write": true】【不是只读模式,会报错index test2 must be read-only to shrink index. use \"index.blocks.write=true\""】curl -XPUT '172.16.2.99:9200/my_source_index/_settings?pretty' -H 'Content-Type: application/json' -d'{  "settings": {    "index.routing.allocation.require._name": "node-1",     "index.blocks.write": true   }}'curl -XPOST '172.16.2.99:9200/test2/_shrink/test1?pretty' -H 'Content-Type: application/json' -d'{  "settings": {    "index.number_of_replicas": 0,    "index.number_of_shards": 1,     "index.codec": "best_compression"   },  "aliases": {    "my_search_indices": {}  }}给索引起的别名"aliases": {    "my_search_indices": {}  }curl -XPOST '172.16.2.99:9200/test2/_settings?pretty' -H 'Content-Type: application/json' -d'{  "settings": {},  "aliases": {    "my_search_indices": {}  }}'【delete index】curl -XDELETE '172.16.2.99:9200/test1?pretty'【delete by query】curl -XPOST '172.16.2.99:9200/bank/_delete_by_query?pretty' -H 'Content-Type: application/json' -d'{  "query": {     "match_all": {    }  }}'curl -XPOST 'localhost:9200/twitter,blog/tweet,post/_delete_by_query?pretty' -H 'Content-Type: application/json' -d'{  "query": {    "match_all": {}  }}'curl -XPOST 'localhost:9200/twitter,blog/tweet,post/_delete_by_query?pretty' -H 'Content-Type: application/json' -d'{  "query": {    "match_all": {}  }}'curl -XPOST 'localhost:9200/twitter/_delete_by_query?scroll_size=5000&pretty' -H 'Content-Type: application/json' -d'{  "query": {    "term": {      "user": "kimchy"    }  }}'【cat】curl -XGET '172.16.2.99:9200/_cat/indices/twi*?v&s=index&pretty'Which index has the largest number of documents?curl -XGET 'localhost:9200/_cat/indices?v&s=docs.count:desc&pretty'How much memory is used per index?curl -XGET 'localhost:9200/_cat/indices?v&h=i,tm&s=tm:desc&pretty'How many merge operations have the shards for the twitter completed?curl -XGET 'localhost:9200/_cat/indices/twitter?pri&v&h=health,index,pri,rep,docs.count,mt&pretty'【cat recovery】curl -XGET '172.16.2.99:9200/_cat/recovery?v'------------------------------------[root@Vm99 bin]# curl -XGET '172.16.2.99:9200/_cat/recovery?v'index               shard time  type           stage source_host source_node target_host target_node repository snapshot files files_recovered files_percent files_total bytes bytes_recovered bytes_percent bytes_total translog_ops translog_ops_recovered translog_ops_percenttest2               0     295ms existing_store done  n/a         n/a         172.16.2.99 node-1      n/a        n/a      0     0               100.0%        10          0     0               100.0%        73797       0            0                      100.0%test2               1     394ms existing_store done  n/a         n/a         172.16.2.99 node-1      n/a        n/a      0     0               100.0%        10          0     0               100.0%        79051       0            0                      100.0%test2               2     326ms existing_store done  n/a         n/a         172.16.2.99 node-1      n/a        n/a      0     0               100.0%        13          0     0               100.0%        81701       0            0                      100.0%.kibana             0     268ms existing_store done  n/a         n/a         172.16.2.99 node-1      n/a        n/a      0     0               100.0%        7           0     0               100.0%        7817        0            0                      100.0%filebeat-2017.06.22 0     176ms empty_store    done  n/a         n/a         172.16.2.99 node-1      n/a        n/a      0     0               0.0%          0           0     0               0.0%          0           0            0                      100.0%filebeat-2017.06.22 1     217ms empty_store    done  n/a         n/a         172.16.2.99 node-1      n/a        n/a      0     0               0.0%          0           0     0               0.0%          0           0            0                      100.0%filebeat-2017.06.22 2     209ms empty_store    done  n/a         n/a         172.16.2.99 node-1      n/a        n/a      0     0               0.0%          0           0     0               0.0%          0           0            0                      100.0%filebeat-2017.06.22 3     149ms empty_store    done  n/a         n/a         172.16.2.99 node-1      n/a        n/a      0     0               0.0%          0           0     0               0.0%          0           0            0                      100.0%filebeat-2017.06.22 4     141ms empty_store    done  n/a         n/a         172.16.2.99 node-1      n/a        n/a      0     0               0.0%          0           0     0               0.0%          0           0            0                      100.0%test1               0     300ms local_shards   done  n/a         n/a         172.16.2.99 node-1      n/a        n/a      0     0               100.0%        33          0     0               100.0%        235792      -1           0   ------------------------------------curl -XGET '172.16.2.99:9200/_cat/recovery?v&h=i,s,t,ty,st,shost,thost,f,fp,b,bp'------------------------------------[root@Vm99 bin]# curl -XGET '172.16.2.99:9200/_cat/recovery?v&h=i,s,t,ty,st,shost,thost,f,fp,b,bp'i                   s t     ty             st   shost thost       f fp     b bptest2               0 295ms existing_store done n/a   172.16.2.99 0 100.0% 0 100.0%test2               1 394ms existing_store done n/a   172.16.2.99 0 100.0% 0 100.0%test2               2 326ms existing_store done n/a   172.16.2.99 0 100.0% 0 100.0%.kibana             0 268ms existing_store done n/a   172.16.2.99 0 100.0% 0 100.0%filebeat-2017.06.22 0 176ms empty_store    done n/a   172.16.2.99 0 0.0%   0 0.0%filebeat-2017.06.22 1 217ms empty_store    done n/a   172.16.2.99 0 0.0%   0 0.0%filebeat-2017.06.22 2 209ms empty_store    done n/a   172.16.2.99 0 0.0%   0 0.0%filebeat-2017.06.22 3 149ms empty_store    done n/a   172.16.2.99 0 0.0%   0 0.0%filebeat-2017.06.22 4 141ms empty_store    done n/a   172.16.2.99 0 0.0%   0 0.0%test1               0 300ms local_shards   done n/a   172.16.2.99 0 100.0% 0 100.0%------------------------------------【aliases】curl -XPOST '172.16.2.99:9200/_aliases?pretty' -H 'Content-Type: application/json' -d'{    "actions" : [        { "add" : { "index" : "test3", "alias" : "my_search_indices" } }    ]}'curl -XPOST '172.16.2.99:9200/_aliases?pretty' -H 'Content-Type: application/json' -d'{    "actions" : [        { "remove" : { "index" : "test3", "alias" : "my_search_indices" } }    ]}'【reindex】curl -XPOST '172.16.2.99:9200/_reindex?pretty' -H 'Content-Type: application/json' -d'{  "source": {    "index": "test2"  },  "dest": {    "index": "test3"  }}'----------------------------------//另一个集群中copy【【elasticsearch.yaml 中将远程集群添加到白名单】】reindex.remote.whitelist: 172.16.2.97:9200 curl -XPOST '172.16.2.99:9200/_reindex?pretty' -H 'Content-Type: application/json' -d'{  "source": {    "remote": {      "host": "http://172.16.2.97:9200"    },                                  "index": "bank"  },  "dest": {    "index": "bank"  }}'curl -XPOST '172.16.2.99:9200/_reindex?pretty' -H 'Content-Type: application/json' -d'{  "source": {    "remote": {      "host": "http://172.16.2.97:9200"    },                                  "index": "bank",    "size": 10  },  "dest": {    "index": "bank"  }}'------------------------------可以rename fieldcurl -XPOST 'localhost:9200/test/test/1?refresh&pretty' -H 'Content-Type: application/json' -d'{  "text": "words words",  "flag": "foo"}'curl -XPOST 'localhost:9200/_reindex?pretty' -H 'Content-Type: application/json' -d'{  "source": {    "index": "test"  },  "dest": {    "index": "test2"  },  "script": {    "inline": "ctx._source.tag = ctx._source.remove(\"flag\")"  }}'curl -XGET 'localhost:9200/test2/test/1?pretty'{  "found": true,  "_id": "1",  "_index": "test2",  "_type": "test",  "_version": 1,  "_source": {    "text": "words words",    "tag": "foo"  }}【open/close index】curl -XPOST '172.16.2.99:9200/my_index/_close?pretty'curl -XPOST '172.16.2.99:9200/my_index/_open?pretty'【update indice settings】curl -XPUT '172.16.2.97:9200/bank/_settings' -d '{    "index" : {        "number_of_replicas" : 0    }}'【task】curl -XGET 'localhost:9200/_tasks?detailed=true&actions=*reindex&pretty'【load data】curl -XPOST '172.16.2.97:9200/bank/account/_bulk?pretty&refresh' --data-binary "@accounts.json"curl 'localhost:9200/_cat/indices?v'【mapping】curl -XPUT '172.16.2.99:9200/my_index?pretty' -H 'Content-Type: application/json' -d'{  "mappings": {    "user": {       "_all":       { "enabled": false  },       "properties": {         "title":    { "type": "text"  },         "name":     { "type": "text"  },         "age":      { "type": "integer" }        }    },    "blogpost": {       "_all":       { "enabled": false  },       "properties": {         "title":    { "type": "text"  },         "body":     { "type": "text"  },         "user_id":  {          "type":   "keyword"         },        "created":  {          "type":   "date",           "format": "strict_date_optional_time||epoch_millis"        }      }    }  }}'
原创粉丝点击