常用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
                        }
                    }
                }
            }
        }
    }
}
相关推荐
大数据追光猿1 小时前
Python应用算法之贪心算法理解和实践
大数据·开发语言·人工智能·python·深度学习·算法·贪心算法
人类群星闪耀时2 小时前
物联网与大数据:揭秘万物互联的新纪元
大数据·物联网·struts
chenbin5202 小时前
Jenkins 自动构建Job
运维·jenkins
risc1234562 小时前
【Elasticsearch】Search Templates(搜索模板)
elasticsearch
java 凯2 小时前
Jenkins插件管理切换国内源地址
运维·jenkins
陆鳐LuLu5 小时前
日志管理利器:基于 ELK 的日志收集、存储与可视化实战
运维·elk·jenkins
[奋斗不止]6 小时前
Jenkins 配置 Credentials 凭证
jenkins·jenkins 配置凭证
桃林春风一杯酒8 小时前
HADOOP_HOME and hadoop.home.dir are unset.
大数据·hadoop·分布式
桃木山人9 小时前
BigData File Viewer报错
大数据·java-ee·github·bigdata
B站计算机毕业设计超人9 小时前
计算机毕业设计Python+DeepSeek-R1高考推荐系统 高考分数线预测 大数据毕设(源码+LW文档+PPT+讲解)
大数据·python·机器学习·网络爬虫·课程设计·数据可视化·推荐算法