当前位置: 首页 > news >正文

ElasticSearch备考 -- Alias

一、题目

1) Create the alias `hamlet` that maps both `hamlet-1` and `hamlet-2`

Verify that the documents grouped by `hamlet` are 8

2) Configure `hamlet-3` to be the write index of the `hamlet` alias

二、思考

可以通过指定别名,来指向一个或多个索引,可以理解成一个linux系统重软链接。

别名创建三种方式

  • 在创建索引时指定别名
  • 索引模版中创建别名
  • 对已有的索引创建别名

通过分析题目1)可以看出是使用第三种方式。题目2)是使用第一种方式。

三、解题

初始化数据

hamlet-1/_doc/_bulk
{"index":{"_index":"hamlet-1","_id":0}}
{"line_number":"1.1.1","speaker":"BERNARDO","text_entry":"Whos there?"}
{"index":{"_index":"hamlet-1","_id":1}}
{"line_number":"1.1.2","speaker":"FRANCISCO","text_entry":"Nay, answer me: stand, and unfold yourself."}
{"index":{"_index":"hamlet-1","_id":2}}
{"line_number":"1.1.3","speaker":"BERNARDO","text_entry":"Long live the king!"}
{"index":{"_index":"hamlet-1","_id":3}}
{"line_number":"1.2.1","speaker":"KING CLAUDIUS","text_entry":"Though yet of Hamlet our dear brothers death"}hamlet-2/_doc/_bulk
{"index":{"_index":"hamlet-2","_id":4}}
{"line_number":"2.1.1","speaker":"LORD POLONIUS","text_entry":"Give him this money and these notes, Reynaldo."}
{"index":{"_index":"hamlet-2","_id":5}}
{"line_number":"2.1.2","speaker":"REYNALDO","text_entry":"I will, my lord."}
{"index":{"_index":"hamlet-2","_id":6}}
{"line_number":"2.1.3","speaker":"LORD POLONIUS","text_entry":"You shall do marvellous wisely, good Reynaldo,"}
{"index":{"_index":"hamlet-2","_id":7}}
{"line_number":"2.1.4","speaker":"LORD POLONIUS","text_entry":"Before you visit him, to make inquire"}

题目一

Step 1、对已有索引创建别名

POST _aliases
{"actions": [{"add": {"index": "hamlet-1","alias": "hamlet"}},{"add": {"index": "hamlet-2","alias": "hamlet"}}]
}

Step 2、通过查询验证别名

POST hamlet/_count

题目二

方案一:创建索引指定别名

aliases 和 mappings 平级

aliases 中别名中花括号不用写任何内容

PUT /hamlet-3
{"aliases": {"hamlet": {}}, "mappings": {"properties": {"line_number": {"type": "text"},"speaker": {"type": "text"},"text_entry": {"type": "text"}}}
}

方案二:索引指定别名可以写

通过参数"is_write_index": true,可以别名执行写操作

POST /_aliases
{"actions": [{"add": {"index": "hamlet-1","alias": "hamlet"}},{"add": {"index": "hamlet-2","alias": "hamlet"}},{"add": {"index": "hamlet-3","alias": "hamlet","is_write_index": true}}]
}

四、总结

别名创建三种方式,注意每种方式的适用场景

  • 在创建索引时指定别名
  • 索引模版中创建别名
  • 对已有的索引创建别名

参考资料

  • Aliases | Elasticsearch Guide [8.1] | Elastic
  • https://www.elastic.co/guide/en/elasticsearch/reference/8.1/index-templates.html

送一波福利:

福利一

有需要内推JD的同学,可以私信或留言,我帮您内推,流程快!!!

有需要内推JD的同学,可以私信或留言,我帮您内推,流程快!!!

有需要内推JD的同学,可以私信或留言,我帮您内推,流程快!!!

福利二

福利三

http://www.lryc.cn/news/457155.html

相关文章:

  • 使用AI编码,这些安全风险你真的了解吗?
  • 计算机网络实验一:组建对等网络
  • R语言绘制折线图
  • 基于组合模型的公交交通客流预测研究
  • docker环境redis启动失败
  • Pandas库详细学习要点
  • 光路科技TSN交换机:驱动自动驾驶技术革新,保障高精度实时数据传输
  • 【含开题报告+文档+PPT+源码】基于SpringBoot的社区家政服务预约系统设计与实现【包运行成功】
  • 2024最新【Pycharm】史上最全PyCharm安装教程,图文教程(超详细)
  • llama3 implemented from scratch 笔记
  • 照片在线转成二维码展示,更方便分享图片的好办法
  • 『网络游戏』登陆协议制定客户端发送账号密码CMD【19】
  • 独享动态IP是什么?它有什么独特优势吗?
  • gaussdb hccdp认证模拟题(单选)
  • 【斯坦福CS144】Lab1
  • 药箱里的药及其常见药的作用
  • Android屏幕旋转流程(2)
  • gaussdb hccdp认证模拟题(判断)
  • 高效架构设计:JPA 实现单据管理,MyBatis 赋能报表查询的最佳实践
  • 深入理解 CSS 浮动(Float):详尽指南
  • ElasticSearch学习笔记(三)Ubuntu 2204 server elasticsearch集群配置
  • 基于STM32的简易交通灯proteus仿真设计(仿真+程序+设计报告+讲解视频)
  • linux下新增加一块sata硬盘并使用
  • 主从复制遇到的问题点
  • Macbook ToDesk 无法连接网络
  • C++-容器适配器- stack、queue、priority_queue和仿函数
  • C++游戏开发指南
  • k8s的pod管理及优化
  • HTML 常用的块级元素和行内元素
  • js短路求值