"timed_out": false,
"_shards": {
"total": 3,
"successful": 3,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 0.5753642,
"hits": [
{
"_index": "log-20230327",
"_id": "001",
"_score": 0.5753642,
"_source": {
"title": "日志27",
"content": "内容27",
"code": "0000",
"info": "操作成功"
}
},
{
"_index": "log-20230328",
"_id": "001",
"_score": 0.5753642,
"_source": {
"title": "日志28",
"content": "内容28",
"code": "0000",
"info": "操作成功"
}
},
{
"_index": "log-20230329",
"_id": "001",
"_score": 0.5753642,
"_source": {
"title": "日志29",
"content": "内容29",
"code": "0001",
"info": "操作失败"
}
}
]
}
}
数据是不能直接写到别名的索引,如果需要写入数据则需要在创建别名时添加参数 is_write_index 。
别名除了关联多个索引实现组合查询外,还可以用来替换索引 。实现原理很简单,例如:当天的日志已经生成了,现在近三天日志,应该将log-20230327删除,重新添加log-20230330的索引,就实现了替换索引,先创建log-20230330索引:
{
"mappings": {
"properties": {
"title": {
"type": "text"
},
"content": {
"type": "text"
},
"code": {
"type": "keyword"
},
"info": {
"type": "text"
}
}
}
}
POST /log-20230330/_doc/001
{
"title": "日志30",
"content":"内容30",
"code": "0000",
"info":"操作成功"
}
再重新定义索引别名
{
"actions": [
{
"add":{
"index": "log-20230330",
"alias": "last_three_day_log"
}
},{
"add":{
"index": "log-20230329",
"alias": "last_three_day_log"
}
},{
"add":{
"index": "log-20230328",
"alias": "last_three_day_log"
}
},{
"remove":{
"index": "log-20230327",
"alias": "last_three_day_log"
}
}
]
}
{
"acknowledged": true
}
重新查询last_three_day_log就会发现没有log-20230327索引的内容了:
{
"query":{
"match":{
"title":"日志"
}
}
}
{
"took": 11,
"timed_out": false,
"_shards": {
"total": 3,
"successful": 3,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 0.5753642,
"hits": [
{
"_index": "log-20230328",
"_id": "001",
"_score": 0.5753642,
"_source": {
"title": "日志28",
"content": "内容28",
"code": "0000",
"info": "操作成功"
}
},
{
"_index": "log-20230329",
"_id": "001",
"_score": 0.5753642,
"_source": {
"title": "日志29",
"content": "内容29",
"code": "0001",
"info": "操作失败"
}
},
{
"_index": "log-20230330",
推荐阅读
- 没有人教你的重要的 Linux 命令
- iOS使用FFmpeg命令行
- Windows常用的一些CMD运行命令
- 如何在 Linux 命令行中查找最大的文件或文件夹
- 永远不要在你的 Linux 系统上运行这些命令
- SQL SERVER日志文件很大20多G日志文件清理 无需分离数据库 SQL命令
- 红色警戒三命令与征服 命运与征服
- 欧美viboss老人 欧美***
- 命令与征服3凯恩之印 凯恩的蹄印
- 魔兽世界坐骑宏命令,魔兽世界坐骑宏