• ES命令行操作


    一、集群管理

    集群状态查询

    # 无密码访问
    $ curl 'localhost:9200/_cat/health?v'
    $ curl 'localhost:9200/_cat/nodes?v'
    $ curl 'localhost:9200/_cat/nodes?v&h=hc,hm,rc,rm'
    
    # 有密码访问
    $ curl 'localhost:9200/_cat/health?v' --user elastic:admin@123
    $ curl 'localhost:9200/_cat/nodes?v' --user elastic:admin@123
    $ curl 'localhost:9200/_cat/nodes?v&h=hc,hm,rc,rm'  --user elastic:admin@123
    

    启动节点

    $ bin/elasticsearch   -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'
    

    二、索引管理

    $ curl 'localhost:9200/_cat/indices?v'
    # 查询索引状态
    $ curl -XDELETE http://localhost:9200/索引名称
    {"acknowledged":true}
    # 删除指定索引
    $ curl -XDELETE http://localhost:9200/索引名称1,索引名称2
    # 删除多个索引,中间用逗号隔开
    $ curl -XDELETE -u elastic:changeme http://localhost:9200/索引名前缀*
    # 模糊匹配删除
    
    # 使用通配符,删除所有索引
    $ curl -XDELETE http://localhost:9200/_all
    $ curl -XDELETE http://localhost:9200/*
    # 二选一都可以
    #  _all ,* 通配所有的索引,通常不建议使用通配符,误删了后果就很严重了,所有的index都被删除了,禁止通配符为了安全起见,可以在elasticsearch.yml配置文件中设置禁用_all和*通配符`action.destructive_requires_name = true`这样就不能使用_all和*了!
    

    创建别名

    $ 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
          }
        }
        }
    }'
    
    $ curl -XGET 'http://localhost:9200/help/_mapping/fulltext?pretty'
    # 获取mapping
    $ curl 'localhost:9200/_cat/shards?v'
    $ curl -XGET 'http://localhost:9200/_cat/shards' | grep INIT
    # 查看分区
    

    三、文档管理

    $ 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": {} }
    }'
    

    四、缓存管理

    创建时显式开启缓存

    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'
    # 查询各节点缓存状态
    

    五、索引副本

    $ curl -XPUT -H 'Content-Type: application/json' 'http://192.168.100.134:9200/entbaseinfo_ceb20200619/_settings' -d'
    {
        "number_of_replicas": 1
    }'
    
    # 指定索引entbaseinfo_ceb20200619副本数为1
    

    六、Es平衡机制

    $ curl -XPUT  -H 'Content-Type: application/json' '192.168.100.134:9200/_cluster/settings' -d'
    {
        "transient" : {
            "cluster.routing.allocation.enable" : "all"
        }
    }'
    
    # 开启es平衡机制
    
    $ curl -XPUT -H 'Content-Type: application/json' '192.168.100.134:9200/_cluster/settings' -d'
    {
        "transient" : {
            "cluster.routing.allocation.enable" : "none"
        }
    }'
    
    # 关闭es平衡机制
    
    *************** 当你发现自己的才华撑不起野心时,就请安静下来学习吧!***************
  • 相关阅读:
    Java实现分布式锁
    Java中拦截器实、过滤器和监听器的实现原理
    Version 28 (intended for Android Pie and below) is the last version of the legacy support library
    AndroidManifest.xml文件报Activity supporting ACTION_VIEW is not set as BROWSABLE
    flowable 流程图片中文乱码
    java 常用工具类 (值得收藏)
    Oracle 创建表空间和用户脚本
    spring cloud alibaba springboot nacos 版本对应
    Tomcat 配置支持不同的域名访问各自不同程序的配置方法
    flowable 表结构说明
  • 原文地址:https://www.cnblogs.com/lvzhenjiang/p/14064208.html
Copyright © 2020-2023  润新知