一、题目
生成快照,或快照生命周期
1.1 考点
(因为这个需要部署共享文件,所以这个我就在虚拟机上简单操作一下)
注: 部署共享文件系统可以看这个文章:NFS 文件共享服务器
1.2 答案
用图形化界面真的很方便,这里是索引通过快照生命周期管理快照
- 运筹
- 快照设置
- 快照保留
- 执行策略
- 检查结果
不知道为啥,这个快照不会自动删除,这个我需要再看一下
二、题目
在集群上有两个索引 index_a 和 index_b,index_a 中有字段 field_a,没有 field_a_desc;index_b 中有 field_a、field_a_desc。其中 index_b 中共有 10 条数据。
要求:
reindex
一个索引 index_c,要求包含 index_a 中的所有数据- index_c 中新增 field_a_desc 字段,且 field_a 的值与 index_b 索引中 field_a 的值相同。
# 创建索引结构
PUT index_a
{
"mappings": {
"properties": {
"field_a":{
"type":"keyword"
},
"field_a-01":{
"type": "keyword"
}
}
}
}
PUT index_b
{
"mappings": {
"properties": {
"field_a":{
"type": "keyword"
},
"field_a_desc":{
"type": "keyword"
}
}
}
}
# 索引数据导入
POST index_a/_bulk
{"index":{"_id":1}}
{"field_a":"a001","field_a_01":"usera01"}
{"index":{"_id":2}}
{"field_a":"a002","field_a_01":"usera02"}
{"index":{"_id":3}}
{"field_a":"a003","field_a_01":"usera03"}
{"index":{"_id":4}}
{"field_a":"a001","field_a_01":"usera011"}
{"index":{"_id":5}}
{"field_a":"a002","field_a_01":"usera012"}
{"index":{"_id":6}}
{"field_a":"a003","field_a_01":"usera013"}
{"index":{"_id":7}}
{"field_a":"a007","field_a_01":"usera021"}
{"index":{"_id":8}}
{"field_a":"a008","field_a_01":"usera022"}
{"index":{"_id":9}}
{"field_a":"a009","field_a_01":"usera023"}
{"index":{"_id":10}}
{"field_a":"a010","field_a_01":"usera031"}
{"index":{"_id":11}}
{"field_a":"a008","field_a_01":"usera032"}
{"index":{"_id":12}}
{"field_a":"a009","field_a_01":"usera033"}
POST index_b/_bulk
{"index":{"_id":1}}
{"field_a":"a001","field_a_desc":"money_01"}
{"index":{"_id":2}}
{"field_a":"a002","field_a_desc":"money_02"}
{"index":{"_id":3}}
{"field_a":"a003","field_a_desc":"money_03"}
{"index":{"_id":4}}
{"field_a":"a004","field_a_desc":"money_04"}
{"index":{"_id":5}}
{"field_a":"a005","field_a_desc":"money_05"}
{"index":{"_id":6}}
{"field_a":"a006","field_a_desc":"money_06"}
{"index":{"_id":7}}
{"field_a":"a007","field_a_desc":"money_07"}
{"index":{"_id":8}}
{"field_a":"a008","field_a_desc":"money_08"}
{"index":{"_id":9}}
{"field_a":"a009","field_a_desc":"money_09"}
{"index":{"_id":10}}
{"field_a":"a010","field_a_desc":"money_10"}
2.1 考点
2.2 答案
# 建立策略
PUT /_enrich/policy/my_policy
{
"match": {
"indices": "index_b",
"match_field": "field_a",
"enrich_fields": ["field_a_desc"]
}
}
# 执行策略
POST /_enrich/policy/my_policy/_execute
# 创建管道
PUT /_ingest/pipeline/index_a_pipeline
{
"processors": [
{
"enrich": {
"policy_name": "my_policy",
"field": "field_a",
"target_field": "new_field",
"max_matches": "1"
}
},
{
"rename": {
"field": "new_field.field_a_desc",
"target_field": "field_a_desc",
"ignore_failure": true
}
},
{
"remove": {
"field": [
"new_field"
],
"ignore_failure": true
}
}
]
}
# 重建索引
POST _reindex
{
"source": {
"index": "index_a"
},
"dest": {
"index": "index_c",
"pipeline": "index_a_pipeline"
}
}
# 检查结果
GET index_c/_search
{
"size": 20
}