Elasticsearch基础11——索引之别名使用

es索引别名操作 这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar 阅读详情
AI摘要

本文深入探讨Elasticsearch中的别名机制,解释其如何帮助无缝切换索引,避免停机升级。涵盖别名的创建、查询、删除、修改,以及通过别名进行数据查询和写入的方法。

Elasticsearch的别名

别名的作用

在之前的文章中,介绍过Elasticsearch索引创建之后,假如尝试修改字段的类型的时候,除了重建索引之外没有别的办法。

假如我们尝试重建一个新的索引并把数据迁移过去,就会出现一个问题,当我们完成数据迁移的时候可能会需要重启我们的环境,将查询目标指向新的索引。假如这个业务已经运行在生产环境中,我们不得不进行一次停机升级。这个对于我们系统的运行来说显然不是很好的方法。

所以Elasticsearch提供了索引别名的功能。索引别名就像一个快捷方式或软连接,可以指向一个或多个索引,也可以给任何一个需要索引名的API来使用。使用索引别名我们可以在运行的集群中无缝的从一个索引切换到另外一个索引。

针对索引的API主要有两种,_alias 用于单个操作, _aliases用于执行多个原子级操作。这点会发现下面两种API都有使用的例子

查询别名

直接调用_aliasAPI的GET方法可以看到索引的别名,下面的例子中就是一个没有创建别名的索引。

查询指定索引的别名

GET localhost:9200/employee/_alias

查询所有索引的别名

GET localhost:9200/_alias
{
    "test_city_info3": {
        "aliases": {}
    },
    "employee": {
        "aliases": {}
    },
    "city_info": {
        "aliases": {}
    }
}

创建别名

这里使用的_aliases方法是一个支持多个别名操作的API。请求参数中接收的是个数组,其可以同时对多个索引添加或者删除别名操作。

  • JSON参数方式

请求地址

POST localhost:9200/_aliases

请求参数

{
    "actions": [
        {
            "add": {
                "index": "employee",
                "alias": "employee_out"
            }
        }
    ]
}
  • 第二种方式

这里使用的_alias方法一次只能操作一个索引。

PUT  localhost:9200/city_info/_alias/city_info_out

再次查询别名

{
    "test_city_info3": {
        "aliases": {}
    },
    "employee": {
        "aliases": {
            "employee_out": {}
        }
    },
    "city_info": {
        "aliases": {
            "city_info_out": {}
        }
    }
}

删除别名

删除别名使用的依旧是_aliasesAPI,需要将add参数修改为remove

请求及参数

POST localhost:9200/_aliases
{
    "actions": [
        {
            "remove": {
                "index": "employee",
                "alias": "employee_out"
            }
        }
    ]
}
DELETE localhost:9200/_aliases

再次查询所有索引的别名

{
    "test_city_info3": {
        "aliases": {}
    },
    "employee": {
        "aliases": {}
    },
    "city_info": {
        "aliases": {}
    }
}

修改别名

其实就是移除之前的别名,然后关联新的别名关系。这一步操作我们可以实现运行中的es集群无缝切换索引。我们可以将索引指向一个新准备的别名中,也可以为别名关联新的索引。

{
    "actions": [
        {
            "remove": {
                "index": "employee",
                "alias": "employee_out"
            }
        },
        {
            "add": {
                "index": "employee",
                "alias": "employee_out2"
            }
        }
    ]
}

另外可以看到索引和别名并非是一对一的关系,一个索引可以对应多个别名,同样一个别名可以对应多个索引。所以就可能出现下面的数据情况

多个索引使用一个别名

{
    "actions": [
        {
            "add": {
                "index": "employee",
                "alias": "employee_out2"
            }
        },
        {
            "add": {
                "index": "city_info",
                "alias": "employee_out2"
            }
        },
        {
            "add": {
                "index": "test_city_info",
                "alias": "employee_out2"
            }
        }
    ]
}

一个索引使用多个别名

{
    "actions": [
        {
            "add": {
                "index": "employee",
                "alias": "employee_out2"
            }
        },
        {
            "add": {
                "index": "employee",
                "alias": "employee_out3"
            }
        },
        {
            "add": {
                "index": "employee",
                "alias": "employee_out4"
            }
        }
    ]
}

通过别名查询索引

一旦一个索引创建了别名,我们就可以通过这个别名获取索引的配置信息。当一个别名对应了多个索引的时候,系统会返回其关联的多个索引的信息。

请求及参数

GET localhost:9200/employee_out3

响应内容

{
    "employee": {
        "aliases": {
            "employee_out2": {},
            "employee_out3": {},
            "employee_out4": {}
        },
        "mappings": {
            "properties": {
                "age": {
                    "type": "integer"
                },
                "entry_time": {
                    "type": "date"
                },
                "group": {
                    "type": "keyword"
                },
                "name": {
                    "type": "keyword"
                }
            }
        },
        "settings": {
            "index": {
                "creation_date": "1571801862644",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "uuid": "FZwM2b8WQQiSnaxMqgbckQ",
                "version": {
                    "created": "7020099"
                },
                "provided_name": "employee"
            }
        }
    }
}

通过别名查询数据

通过别名进行数据查询的时候可以尝试查询出多个索引的数据。现在有个employee_out2它关联了两个完全不同结构的索引,一个之前测试数据的employee索引,一个是之前测试的城市信息索引city_info,现在尝试对这两个完全不一样结构的索引进行查询

请求地址

POST localhost:9200/employee_out2/_search


{
    "query": {
        "terms": {
            "name": [
                "甲0",
                "上海"
            ]
        }
    }
}

返回结果

最后可以看到其拿到了完全不同的数据内容。


{
    ....
    "hits": {
        "total": {
            "value": 5,
            "relation": "eq"
        },
        "max_score": 1,
        "hits": [
            {
                "_index": "city_info",
                "_type": "_doc",
                "_id": "1",
                "_score": 1,
                "_source": {
                    "name": "上海",
                    "desc": "中国经济、金融、贸易、航运、科技创新中心",
                    "province": "上海",
                    "gdp": "3267900000000",
                    "area": "华东地区",
                    "carNumPrefix": "沪"
                }
            },
            {
                "_index": "city_info",
                "_type": "_doc",
                "_id": "7",
                "_score": 1,
                "_source": {
                    "name": "苏州",
                    "desc": "大城市",
                    "province": "江苏",
                    "gdp": "1859700000000",
                    "area": "华东地区",
                    "carNumPrefix": "苏E"
                }
            },
            ....
        ]
    }
}

通过别名写数据

当一个别名关联多个索引的时候,此时需要为索引设置参数is_write_index,被设置为true的索引,当对别名写数据的时候数据会被写到此索引中。

POST localhost:9200/_aliases

{
    "actions": [
        {
            "add": {
                "index": "employee",
                "alias": "employee_out2",
                "is_write_index": true
            }
        }
    ]
}

然后数据插入完成

PUT localhost:9200/employee_out2/_doc/200

{
    "_index": "employee",
    "_type": "_doc",
    "_id": "200",
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 100,
    "_primary_term": 1
}

使用别名重建索引的过程

当我们决定存储某种数据时,在创建索引的时候需要将数据结构完整确定下来,于此同时索引的设定和很多固定配置将不能改变。
当需要改变数据结构时,就需要重新建立索引,为此,Elastic团队提供了很多辅助⼯工具帮助开发人员进行重建索引。

重建索引过程

  1. 为当前索引建立一个别名
  2. 将需要调整后的映射建立一个索引
  3. 将旧索引的数据同步到新索引中
  4. 将新索引和当前索引别名关联
  5. 删除旧索引,完成数据转移
创建索引以及映射
PUT  localhost:9200/user


{
    "properties": {
        "name": {
            "type": "keyword"
        },
        "age": {
            "type": "integer"
        },
        "role": {
            "type": "integer"
        }
    }
}

创建别名
POST localhost:9200/_aliases
{
    "actions": [
        {
            "add": {
                "index": "user",
                "alias": "user_out",
                "is_write_index": true
            }
        }
    ]
}
插入一些数据

…

新的索引映射
PUT  localhost:9200/user_v2


{
    "properties": {
        "name": {
            "type": "keyword"
        },
        "age": {
            "type": "integer"
        },
        "role": {
            "type": "keyword"
        }
    }
}

拷贝数据
POST localhost:9200/_reindex

{
    "source": {
        "index": "user"
    },
    "dest": {
        "index": "user_v2"
    }
}
进行别名替换
POST localhost:9200/_aliases
{
    "actions": [
        {
            "add": {
                "index": "user_v2",
                "alias": "user_out"
            }
        },
        {
            "remove": {
                "index": "user",
                "alias": "user_out"
            }
        }
    ]
}

当一个别名关联多个索引的时候,进行查询

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Alias [employee_out2] has more than one indices associated with it [[employee, test_city_info, city_info]], can't execute a single index op"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Alias [employee_out2] has more than one indices associated with it [[employee, test_city_info, city_info]], can't execute a single index op"
    },
    "status": 400
}

删除索引(错误内容)

POST localhost:9200/user

访问数据
GET localhost:9200/user_out/_doc/1

个人水平有限,上面的内容可能存在没有描述清楚或者错误的地方,假如开发同学发现了,请及时告知,我会第一时间修改相关内容。假如我的这篇内容对你有任何帮助的话,麻烦给我点一个赞。你的点赞就是我前进的动力。

【ELK报错】Alias [.kibana] has more than one indices associated with it [[.kibana_1, .kibana_2]] 错误复现 搭建1套新的ELK环境,将之前旧的ES的索引文件data/nodes/0/indices/全部复制到新的ES中。期间不要停止ES。然后kibana就无法访问了,重启kibana报错如下: log [02:59:35.875] [info][status][plugin:maps@6.7.2] Status changed from yellow to green - Ready ... 阅读详情

相关推荐

Elasticsearch别名(aliases)使用

目录 一、概述 二、索引别名相关 API 一、概述 在ES中,索引别名(index aliases)就像一个快捷方式或软连接,可以指向一个或多个索引。别名带给我们极大的灵活性,我们可以使用索引别名实现以下功能: (1)在一个运行中的ES集群中无缝的切换一个索引到另一个索引上(无需停机) 例如,在生产环境中,为了避免索引里面的数据和数据库中的数据不一致,运维每天都要重建一遍ES索引。又比如项目中使用的老的索引,需要重建索引,这样必然需要更新dao层查询中的索引名称,然后重新启动应用,可能会对服务的使

weixiaohuai的博客 1万+

Elasticsearch中别名alias相关操作(创建、更新、删除)

Elasticsearch中别名alias相关操作(创建、更新、删除)

IT之一小佬的博客 1万+

【Elasticsearch从入门到精通】第11篇:Elasticsearch索引API详解——索引创建、删除与别名管理

摘要 索引管理是Elasticsearch运维的核心技能。本文系统介绍了索引全生命周期管理的关键操作:从索引创建(包括命名规范、settings和mappings配置)、索引删除与状态判断,到高级功能如索引收缩和别名管理。重点讲解了别名的多种应用场景,包括基本别名、过滤别名(实现数据视图隔离)和路由别名(优化查询性能),并提供了完整的REST API示例。通过合理使用这些功能,可以实现零停机索引重建、数据分片优化等生产环境常见需求,为Elasticsearch集群的高效运维提供完整解决方案。

xyghehehehe的专栏 520

ElasticSearch|别名 (alias) 的常用命令及语法

是 *数据流(data streams)*或 *索引(indices)*的另一个名称,大多数 ElasticSearch API 可以使用别名替代数据流或索引名称。选项将索引的别名的请求路由到特定分片,可以利用分片缓存加速搜索。参数来指定对别名的写入请求将写入哪个索引或数据流,写入请求最终只会被路由到添加了。为已存在的数据流或索引添加别名,可以使用 aliases API 的。后添加数据流或索引名,查询该别名对应的索引名或数据流。前添加数据流或索引名,查询指定数据流或索引名的别名。参数的索引或数据流上。

长行 2045

Spine动画在Unity里卡顿、闪烁、排序错乱?这些性能优化与渲染问题一次讲清

本文深入解析了Spine动画在Unity中常见的卡顿、闪烁和排序错乱问题,提供了全面的性能优化与渲染解决方案。从性能瓶颈诊断到材质合并、动态合批优化,再到层级错乱与Alpha闪烁的处理,帮助开发者提升动画表现和运行效率。特别针对Unity和Spine的协同工作进行了详细的技术探讨。

weixin_29967445的博客 385

K8s私有仓库拉取镜像报错解决:x509 certificate signed by unknown authority

在Kubernetes环境中使用自签名证书的私有Harbor镜像仓库时,常会遇到证书验证失败的问题。本文将详细讲解如何解决这个常见的证书问题。Kubernetes版本:1.28.2容器运行时:containerd 1.6.20私有仓库:Harbor(使用自签名证书)(超简单搭建私有仓库Harbor-亲测无坑解决K8s私有仓库证书问题的关键在于正确配置容器运行时(本例中是containerd)信任私有仓库的证书。

lzz的博客 2143

es 索引别名

别名是指给一个或者多个索引定义另外一个名称,使索引别名和索引之间可以建立某种逻辑关系。 可以用别名表示别名和索引之间的包含关系。例如,我们建立了10月、11月、12月的用户入住酒店的日志索引,假设需要搜索这3个月的日志索引,如果分别去3个索引中进行搜索,这种编码方案比较低效。此时可以创建一个别名4_quarter,设置前面的3个索引的别名为4_quarter,然后在4_quarter中进行搜索即...

xc_oo0的博客 72

实战指南:UOS专业版命令行高效下载离线安装包及依赖

本文提供了一份UOS专业版离线安装包的实战下载指南。针对无外网环境下的软件部署难题,详细介绍了如何通过命令行精准获取软件包名,并利用`apt download`命令高效下载主程序及其所有依赖。文章重点解析了使用`apt install --dry-run`模拟安装来完整获取依赖包的方法,并给出了离线安装、问题排查及自动化脚本编写等高级技巧,帮助管理员和运维人员实现可靠的批量离线部署。

honey的博客 1117

Elasticsearch企业级项目实战:从索引设计到Spring Boot搜索服务

在分布式搜索引擎的工程落地中,环境搭建只是起点,真正决定项目成败的是数据建模与检索链路的设计。Elasticsearch作为高扩展的全文检索组件,其索引字段类型、中文分词策略以及Java客户端集成方式,直接影响查询效率和业务稳定性。从商城商品搜索场景出发,讲解keyword与text的选型、IK分词器的配置、Spring Boot官方API的接入,并给出组合查询、过滤上下文、高亮排序及快照恢复的完整实现。通过别名切换与数据备份保障索引可运维性,帮助开发者构建一套具备生产能力的搜索服务,而非停留在查询Demo

weixin_33178839的博客 215

智能气象站:ESP32驱动的心知天气数据可视化实践

本文详细介绍了基于ESP32微控制器和心知天气API构建智能气象站的完整实践。通过Arduino开发环境,实现天气数据的获取、JSON解析与OLED屏可视化展示,涵盖硬件连接、API配置、低功耗优化及部署问题排查,为物联网开发者提供实用指南。

jump7的博客 214

Tinder养号防封攻略来了:最新Tinder养号流程和运营攻略

今天,我就来给大家分享一下Tinder养号的具体操作,以及针对Tinder账号被封的一些常见问题为大家做个答疑。

m0_67768117的博客 2万+

Elasticsearch 别名查询与写入索引检查

Elasticsearch 别名查询与写入索引检查

Leon_Jinhai_Sun的博客 826

Python气象数据处理实战:用PyCINRAD轻松绘制雷达PPI图像(附避坑指南)

本文详细介绍了如何使用Python库PyCINRAD处理中国CINRAD系列天气雷达的基数据,并绘制专业的PPI图像。内容涵盖从环境配置、数据读取、核心绘图到高级定制与批量处理的完整流程,并针对安装依赖、中文乱码、数据范围等常见问题提供了实用的避坑指南,帮助气象工作者高效完成雷达数据可视化。

dog123的博客 226

如何理解 EigenFlux 的 Elasticsearch 设计:ILM 索引生命周期与向量相似度搜索完整指南

在 AI Agent 通信网络 **EigenFlux** 中,每条广播(item)都会被写入 **Elasticsearch**,并通过 **ILM 索引生命周期管理**自动在 Hot → Warm → Cold 三阶段间流转,同时借助 **向量相似度搜索(kNN + cosine)**实现跨索引的语义去重与分组。本文带你用最短时间看懂这套存储架构的设计思路、读写分离的别名架构,以及向量搜索在

gitblog_00143的博客 119

WebRTC之beamforming算法

CSND已永久停更,最新版唯一来源点击下面链接跳转: 语音增强和语音识别网页书 坐标问题 这里以笔记本为例进行说明,当笔记本按如下方式打开: 首先是键盘和液晶屏呈90度,然后鼠标上方,也就是液晶屏上方正中间是camera,把平行于键盘的面看成是xy平面,把液晶屏所在的面看成是xz平面,所有平面的原点都在Camera的位置。 方位角:从原点开始,Camera的右侧是0度,逆时针方...

shichaog的专栏 1万+

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

ES索引切分方案2:时序数据自动化管理:索引别名 结合 索引生命周期管理(ILM) 的滚动(Rollover)机制

详解如何用Elasticsearch ILM策略+Rollover机制+索引别名实现时序数据自动分片、滚动、归档,提供完整JSON配置、别名写入、搜索示例及1分钟级优化技巧,助你零人工干预管理PB级日志与文件数据。

每个人都是独一无二的,把握好自己的节奏,跟着自己的心走。 1126

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Elasticsearch 的索引管理与映射配置实战

本文介绍了 Elasticsearch 中索引与映射的基本概念及其重要性。通过详细的操作示例,阐述了如何创建、更新和删除索引,以及如何定义和调整映射以优化数据存储与查询性能。文章强调了选择适当数据类型和字段属性、动态映射调整的重要性,以及索引生命周期管理(ILM)对提升性能的作用。希望读者能够掌握这些基础知识,提升数据管理和搜索效率。

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 6万+

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Elasticsearch - Elasticsearch 索引别名 灵活管理索引的技巧

Elasticsearch索引别名是一种强大的逻辑名称功能,可以指向一个或多个物理索引,实现灵活的索引管理。本文介绍了索引别名的核心概念、典型应用场景与Java客户端操作实践。主要内容包括:别名与索引的区别、零停机重建索引的实现原理、时间序列数据的统一查询方法,以及通过Java API Client进行别名创建、切换和查询的详细代码示例。掌握索引别名技术能够有效解决索引更新、灰度发布和查询聚合等实际工程问题,提升搜索系统的可用性和可维护性。

千淘万漉虽辛苦,吹尽狂沙始到金 2万+

ES查询 索引别名

es curl使用

KANGBboy的博客 1634

Elasticsearch 6: 索引别名

目录1. 创建索引添加别名2. 为已有索引添加别名3. 查询指定索引的别名4. 删除别名5. 查询别名6. 通过别名查询7. _aliases 接口8. 结合路由和别名9. _rollover 接口 别名,有点类似数据库的视图,别名一般都会和一些过滤条件相结合,可以做到即使是同一个索引上,让不同人看到不同的数据。别名的访问接口是_alias。 1. 创建索引添加别名 PUT /index_alias { "aliases": { "index1": { "

Fisher3652的博客 2662

ElasticSearch的REST APIs 之 索引的别名(alias)管理

基于 ES 7.7, 官方文档 注意: 7.15版本中调整了分类, 把7.7版本中的Add和Update合并为"Create or Update",...

aben_sky的专栏 2232

架构师系列-搜索引擎ElasticSearch(十)- 索引别名及重建

别名,有点类似数据库的视图,别名一般都会和一些过滤条件相结合,可以做到即使是同一个索引上,让不同人看到不同的数据。

dengwei_dw的专栏 1166

elasticsearch索引的基本操作以及别名的使用

在上篇文章写了关于elasticsearch索引的数据类型,这里就详细说下索引的增删改查以及其他的一些操作吧。

weixin_43360488的博客 1018

ElasticSearch使用别名进行索引数据迁移

ElasticSearch 版本为 7.8.1。 Kibana 版本为 7.8.1。 这些命令都是在Kibana下的控制台进行测试的。 关于ElasticSearch集群的搭建和Kibana的使用可以看我的其他文章。 1、动态创建索引my_68_idx并添加数据 PUT /my_68_idx/_doc/1 { "title":"2020-09-01" } 添加日期字符串 2、再次添加一条数据 PUT /my_68_idx/_doc/1 { "title":"this is a string.

Coding Earth Engine 1412

项目实战:基于elasticsearch打造亿级搜索引擎系统(附全套源码)

一,前言 Elasticsearch是一个基于Lucene的分布式可扩展的实时搜索和分析引擎,。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。Elasticsearch用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。官方客户端在Java、PHP、Python、Ruby和许多其他语言中都是可用的。Elasticsearch是最受欢迎的企业搜索引

大团猿的博客 5877
上一篇: Elasticsearch嵌套字段的聚合操作
下一篇: Elasticsearch基础12——kibana安装和使用
大·风
博客等级 码龄17年 255粉丝 282原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大·风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
⌂ 换网址