【ElasticSearch的点点滴滴】第三篇:POST相关操作

  1. 修改指定文档
POST /test/t_tuser/201803291940090320/_update
{
  "doc":{
    "m_acc":"mailtest@qq.com"
  }
}
curl命令
curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
    "doc" : {
        "name" : "new_name"
    }
}'
  1. 打开/关闭索引
POST /test_index_201702_001/_open
POST /test_index_201702_001/_close
  1. 数据同步
关闭数据同步
PUT /_cluster/settings
{
    "transient" : {
        "cluster.routing.allocation.enable" : "none"
    }
}
curl -XPUT http://172.168.1.144:9200/_cluster/settings -d'
{
    "transient" : {
        "cluster.routing.allocation.enable" : "none"
    }
}'
开启数据同步
PUT /_cluster/settings
{
    "transient" : {
        "cluster.routing.allocation.enable" : "all"
    }
}
curl -XPUT http://172.168.1.121:9200/_cluster/settings -d'
{
    "transient" : {
        "cluster.routing.allocation.enable" : "all"
    }
}'
  1. 移动分片
curl -XPOST 'http://localhost:9200/_cluster/reroute' -d '{
  "commands":[{
  "move":{
    "index":"indexName",
    "shard":0,
    "from_node":"node-1",
    "to_node":"node-4"
}}]}'
curl -XPOST 'localhost:9200/_cluster/reroute' -d 'xxxxxx' 
对shard的手动控制,参考[http://zhaoyanblog.com/archives/687.html](http://zhaoyanblog.com/archives/687.html)
  1. 关闭集群或节点
关闭指定192.168.1.1节点 
curl -XPOST 'http://192.168.1.1:9200/_cluster/nodes/_local/_shutdown' 
curl -XPOST 'http://localhost:9200/_cluster/nodes/192.168.1.1/_shutdown' 
关闭主节点 
curl -XPOST 'http://localhost:9200/_cluster/nodes/_master/_shutdown' 
关闭整个集群 
curl -XPOST 'http://localhost:9200/_shutdown?delay=10s' 
curl -XPOST 'http://localhost:9200/_cluster/nodes/_shutdown' 
curl -XPOST 'http://localhost:9200/_cluster/nodes/_all/_shutdown'
delay=10s表示延迟10秒关闭
  1. mapping增加字段
POST /index_test/www/_mapping
{
  "properties": {
    "content": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "text",
                "analyzer": "key_analyzer"
              },
              "sortword": {
                "type": "keyword"
              }
            },
            "analyzer": "text_analyzer"
          }
  }
}
  1. es开启慢查询日志
PUT /_cluster/settings
{
    "transient" : {
        "logger.discovery" : "DEBUG"
    }
}
8. 索引增加/删除别名
增加别名
POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "test_search_index",
        "alias": "my_index_alias"
      }
    }
  ]
}
删除别名
POST /_aliases
{
  "actions": [
    {
      "remove": {
        "index": "test_send_lms",
        "alias": "MC_test317_test_index"
      }
    }
  ]
}
  1. 更新文档
POST /test_201803/mail/6538317985629667366/_update
{
  "doc":{
    "m_acc":"mailtest@qq.com"
  }
}
脚本更新
PUT test/type1/1
{
    "counter" : 1,
    "_counter_conf":10,
      "tags" : ["red"],
      "_tags_conf":10
}
POST test/type1/1/_update
{
    "script" : {
        "inline": "ctx._source.counter += params.count",
        "lang": "painless",
        "params" : {
            "count" : 4
        }
    }
}
POST test/type1/1/_update
{
    "script" : {
       "inline": "ctx._source.tags.add(params.tag)",
        "lang": "painless",
        "params" : {
            "tag" : ""
        }
    }
}
POST test/type1/1/_update
{
    "script" : "ctx._source.new_field = \"value_of_new_field\""
}
POST test_scripts/t_vitualacc/all_3941749185576961,1ilhw9tu0z7_EBANK_ALIPAY/_update
{
    "script" : {
        "inline": "if(ctx._source.type_conf<params.type_conf){ctx._source.type=params.type;ctx._source.type_conf=params.type_conf} if(ctx._source.id_conf<params.id_conf){ctx._source.id = params.id;ctx._source.id_conf=params.id_conf} if(ctx._source.account_conf<params.account_conf){ctx._source.account=params.account;ctx._source.account_conf=params.account_conf}",
        "lang": "painless",
        "params" : {
            "account_conf" : 11,
            "account": "1ilhw9tu0z7777",
            "type_conf":10,
            
            "id_conf":10
        }
    }
}
  1. 设置快照库
设置快照库
PUT _snapshot/share_data 
{
    "type": "fs", 
    "settings": {
        "location": "/home/esdata/share_data" 
    }
}
POST _snapshot/share_data/snapshot_2/_restore
索引状态管理
Clear Cache 清理缓存
POST /twitter/_cache/clear
默认会清理所有缓存,可指定清理query, fielddata or request 缓存
POST /kimchy,elasticsearch/_cache/clear
POST /_cache/clear
Refresh,重新打开读取索引
POST /kimchy,elasticsearch/_refresh
POST /_refresh
Flush,将缓存在内存中的索引数据刷新到持久存储中
POST twitter/_flush
Force merge 强制段合并
POST /kimchy/_forcemerge?only_expunge_deletes=false&max_num_segments=100&flush=true
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值