常用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}/_mapping和GET /{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是你原索引的名字,需要去除,将settings和mappings放在最外层,再加一个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
                        }
                    }
                }
            }
        }
    }
}
相关推荐
IT大白鼠28 分钟前
搜索系列 · 第 04 篇——部署实操:内网集群落地
运维·elasticsearch·nosql
径硕科技JINGdigital30 分钟前
出海企业想要借助统一平台接入国际主流基础模型,可选哪些云上生成式 AI 平台?
大数据·人工智能
Elastic 中国社区官方博客43 分钟前
使用 Jev 作为 search reranker:基准测试与实现方法
大数据·运维·elasticsearch·全文检索
卷毛迷你猪1 小时前
快速实验篇(B01)用户行为日志画像与 DWD 标准化
大数据·hive·hadoop
四季豆331 小时前
中翰软件调整战略定位:以数据与知识“双治理”搭建企业AI落地桥梁
大数据
T06205142 小时前
【2026年更新】全国自然保护区矢量数据,列表+边界+功能区
大数据
ha_lydms2 小时前
MaxCompute中JSON函数
大数据·数据库·阿里云·json·dataworks·maxcompute·odps
H0311169852 小时前
移动应用数据分析平台信息整理:月狐数据、七麦数据、蝉大师
大数据·人工智能
小宋10212 小时前
Jev 不是另一个聊天模型:Choice、Score、Boolean 与概率决策完整实战
大数据·人工智能
数字化顾问3 小时前
(136页PPT)BCGIDG资本中国某省市场Geneva项目商业尽职调查项目报告(附下载方式)
大数据·人工智能