常用es命令

常用Elasticsearch命令

es别名链接和删除

json 复制代码
POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "index",
        "alias": "alias"
      }
    },
    {
      "remove": {
        "index": "index",
        "alias": "alias"
      }
    }
  ]
}

其中,一个POST请求中的actions按顺序执行,这使得可以无缝切换或者更新索引的别名,或者批量操作。索引可以使用GET /_cat/aliases?v查看。

索引迁移

索引直接迁移

json 复制代码
POST _reindex?wait_for_completion=false
{
  "source": {
    "size": 5000,
    "remote": {
      "host": "http://es.com:80",
      "username": "elastic",
      "password": "123456"
    },
    "index": "原索引名"
  },
  "dest": {
    "index": "目标索引名"
  }
}

其中:

  1. POST _reindex?wait_for_completion=false用于重新索引文档。wait_for_completion=false是一个查询参数,表示这个操作是异步的,API调用会立即返回一个任务ID,你可以通过这个任务ID来查询操作的进度。查询方法为GET /_tasks/{task_id}
  2. "source"代表源索引的信息;"size"指定了每次批量获取的文档数量,这里为5000;"remote"包含了远程Elasticsearch集群的连接信息;"host"指定远程Elasticsearch集群的地址和端口;"username"和"password"提供用于连接远程Elasticsearch集群的用户名和密码;"index"指定原索引;"dest"指定目标索引。

在使用这个API时,确保你的Elasticsearch集群安全设置允许这种操作,并且你有权限访问源索引和目标索引。此外,如果目标索引已经存在,Elasticsearch默认会失败,除非你使用op_type=index参数来覆盖已有文档。

只复制索引参数

首先你需要使用GET /{index}/_mappingGET /{index}/_settings获取索引的映射信息和设置信息,其中记得在settings中剔除index.creation_date、index.uuid、index.version.created、index.version.upgraded、index.provided_name几个字段,这属于索引自动创建的,不能在创建新索引时使用,其样式可能为:

settings:

json 复制代码
{
  "test_index" : {
    "settings" : {
      "index" : {
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "version" : { }
      }
    }
  }
}

mappings

json 复制代码
{
    "test_index": {
        "mappings": {
            "test_index": {
                "properties": {
                    "id": {
                        "type": "long"
                    },
                    "content": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    }
                }
            }
        }
    }
}

其中最外层的test_index是你原索引的名字,需要去除,将settingsmappings放在最外层,再加一个PUT {index}命令就可以复制索引结参数了,即

json 复制代码
PUT  {index}
{
    "settings": {
        "index": {
            "number_of_shards": "5",
            "number_of_replicas": "1",
            "version": {

            }
        }
    },
    "mappings": {
        "{index}": {
            "properties": {
                "id": {
                    "type": "long"
                },
                "content": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        }
    }
}
相关推荐
yantaohk8 分钟前
普通人怎么利用PCDN赚钱?几个接地气的案例告诉你
大数据·网络
xiangzhihong89 分钟前
Claude Code系列教程之Claude Code并行任务
大数据·elasticsearch·搜索引擎
计算机毕业编程指导师17 分钟前
【大数据毕设推荐】Hadoop+Spark电影票房分析系统,Python+Django全栈实现 毕业设计 选题推荐 毕设选题 数据分析 机器学习 数据挖掘
大数据·hadoop·python·计算机·spark·毕业设计·电影票房
yantaohk30 分钟前
PCDN还能赚钱吗?普通人用闲置宽带赚钱的机会、收益和风险分析
大数据·人工智能·内容运营
PythonFun1 小时前
告别加班!3分钟搞定百余份荣誉证书,WPS这个组合功能太强了
大数据·wps
csgo打的菜又爱玩1 小时前
11.JobManager 启动流程总结
大数据·开发语言·qt·microsoft·flink
OneBlock Community1 小时前
重磅!SEC & CFTC 联手“定义加密”,Polkadot 被写进规则!
大数据·人工智能
牛奶咖啡131 小时前
CI/CD——使用Jenkins自动化构建java项目之使用传统方式部署java web项目jpress
ci/cd·jenkins·jenkins创建任务·实现jpress的自动化部署·git的ssh主机密钥问题解决·配置ssh免密登录·在线安装jdk1.8环境
弹简特2 小时前
【精通Postman接口测试】04-Postman的CLI命令+Jenkins和Newman+Allure+Jenkins自动化接口持续集成
自动化·jenkins·接口测试·postman
Elasticsearch2 小时前
Elasticsearch ES|QL 视图:一个查询统领十二个仪表板
elasticsearch