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

【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_percent
test2               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 bp
test2               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 field
curl -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"
        }
      }
    }
  }
}
'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值