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

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.kler.cn/news/336313.html

相关文章:

  • vulnhub-Sputnik 1靶机
  • CPU、GPU、显卡
  • 【QT Qucik】C++交互:接收QML信号
  • 四川全寄宿自闭症学校专业团队详解
  • 数学概念算法-打印100以内的素/质数
  • 【QT Quick】基础语法:`default`属性
  • C#医学影像分析源码,医院影像中心PACS系统源码
  • 什么是汽车中的SDK?
  • ‌在Python中,print(f‘‘)是什么?
  • 大模型面试宝典:问题全集及权威解答
  • ctf.bugku-备份是个好习惯
  • Lua语言中函数的二进制码保存与查看
  • vue3 挂载全局公共方法/变量/数据
  • qemu模拟arm64环境-构建6.1内核以及debian12
  • 图吧工具箱
  • RHCSA的学习(2)
  • 在远程非桌面版Ubuntu中使用Qt5构建Hello World项目
  • 系统架构设计师论文《论企业应用系统的数据持久层架构设计》精选试读
  • Sollong手机——一站式Web3生态解决方案
  • 基于深度学习多层感知机进行手机价格预测