es 常用命令

curl 'localhost:9200/_cat' 查询管理命令列表


1.集群管理
集群状态查询
curl 'localhost:9200/_cat/health?v'
curl '192.168.56.10:9200/_cat/nodes?v'
curl '192.168.56.10:9200/_cat/nodes?v&h=hc,hm,rc,rm'




启动节点
bin/elasticsearch     -Des.cluster.name=es4fql   -Des.node.name=n_4.216  -d
关闭节点
curl -XPOST 'http://localhost:9200/_cluster/nodes/n2/_shutdown'
curl -XPOST 'http://localhost:9200/_shutdown'
curl -XPOST 'http://localhost:9200/_cluster/nodes/_local/_shutdown?delay=10s'




2.索引管理
查询索引状态
curl 'localhost:9200/_cat/indices?v'


创建索引
curl -XPUT 'localhost:9200/goods_v1?pretty'


删除索引
curl -XDELETE 'localhost:9200/goods_v1?pretty'


创建别名
curl -XPOST localhost:9200/_aliases -d '
{
    "actions": [
        { "add": {
            "alias": "goods",
            "index": "goods_v1"
        }}
    ]
}
'
删除并更新别名
curl -XPOST 'http://localhost:9200/_aliases' -d '
{
    "actions" : [
        { "remove" : { "index" : "goods_v2", "alias" : "goods" } },
        { "add" : { "index" : "goods_v1", "alias" : "goods" } }
    ]
}'


查看已有别名
curl -XGET 'localhost:9200/_cat/aliases'


查看别名对应的索引
curl -XGET 'localhost:9200/_alias/help'




创建mapping
curl -XPOST http://localhost:9200/goods_v1/fulltext/_mapping -d'
{
    "fulltext": {
             "_all": {
            "indexAnalyzer": "ik",
            "searchAnalyzer": "ik_syno",
            "term_vector": "no",
            "store": "false"
        },
     "properties": {
        "sku_id" :{
          "type": "string"
      },
      "product_id":{
          "type": "string"
      },
      "product_name":{
          "type": "string",
          "store": "no",
          "term_vector": "with_positions_offsets",
          "indexAnalyzer": "ik",
          "searchAnalyzer": "ik_syno",
          "include_in_all": "true",
          "boost": 8
      }
    }
    }
}'




获取mapping
curl -XGET 'http://localhost:9200/help/_mapping/fulltext?pretty'




查看分区
curl 'localhost:9200/_cat/shards?v'




curl -XGET 'http://localhost:9200/_cat/shards' | grep INIT




修复unsigned 分区
for shard in $(curl -XGET http://localhost:9200/_cat/shards | grep UNASSIGNED | grep goods_v1 |awk '{print $2}'); do
    curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
        "commands" : [ {
              "allocate" : {
                  "index" : "goods_v1", 
                  "shard" : $shard, 
                  "node" : "n_4.216", 
                  "allow_primary" : false
              }
            }
        ]
    }'
    sleep 5
done


curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
        "commands" : [ {
              "allocate" : {
                  "index" : "goods", 
                  "shard" : 2, 
                  "node" : "n2", 
                  "allow_primary" : false
              }
            }
        ]
    }'




索引修复
java -cp lucene-core-4.10.4.jar -ea:org.apache.lucene... org.apache.lucene.index.CheckIndex /opt/elasticsearch-1.5.0/data/elasticsearch/nodes/0/indices/goods_v2/2/index -fix


解决unsigned 分区的问题
curl -XPUT 'localhost:9200/<index>/_settings' \
    -d '{"index.routing.allocation.disable_allocation": false}'


3.文档管理
获取文档
curl -XGET 'localhost:9200/goods/fulltext/S201406251699?pretty'
删除文档
curl -XDELETE 'localhost:9200/goods/fulltext/1?pretty'


获取索引中前10个文档
curl -XPOST 'localhost:9200/goods/_search?pretty' -d '
{
  "query": { "match_all": {} }
}'


4.缓存管理
创建时显式开启缓存
curl -XPUT localhost:9200/my_index -d'
{
  "settings": {
    "index.cache.query.enable": true
  }
}
'
更新设置开启缓存
curl -XPUT localhost:9200/goods/_settings -d'
{ "index.cache.query.enable": true }
'


查询各节点缓存状态
curl 'localhost:9200/_nodes/stats/indices/query_cache?pretty&human'
5.分词测试
curl -XGET 'http://localhost:9200/goods/_analyze?analyzer=ik_max_word_syno&pretty' -d '爱疯狂'
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值