索引别名,滚动索引

索引别名——API会自动将别名转换为实际索引名称。

  别名可以映射到多个索引

  别名还可以与过滤器关联,该过滤器在搜索和路由值时自动应用

  别名不能与索引同名

1.创建一个索引的别名

2.删除一个索引的别名

3.重命名一个索引的别名

4.多个索引添加别名

5.创建过滤器别名(带有过滤器的别名,提供了一种简单的方法来创建系统个索引的不同视图。)

6.查询别名

7.滚动索引(当现有的索引太大或太老时,滚动索引将别名滚动到新的索引)

扫描二维码关注公众号,回复: 7519240 查看本文章

1. 创建一个索引的别POST /_aliases{

"actions": [
    {
      "add": {
        "index": "test1",
        "alias": "alias1"
      }
    }
  ]
}
GET _alias
{
"my_index" : {
"aliases" : {
"alias1" : { }
}
},
"test1" : {
"aliases" : {
"alias1" : { }
}
}
 
  
 
 

2.删除一个索引的别名

POST /_aliases
{
  "actions": [
    {
      "remove": {
        "index": "test1",
        "alias": "alias1"
      }
    }
  ]
}

3.重命名一个索引的别名

#新建索引,没有别名
"test2" : {
    "aliases" : { }
  }


POST /_aliases
{
  "actions": [
    {
      "remove": {
        "index": "test1",
        "alias": "alias1"
      }},
    {  "add": {
        "index": "test2",
        "alias": "alias1"
      }
    }
  ]
}

GET _alias

{
  "my_index" : {
    "aliases" : {
      "alias1" : { }
    }
  },
  "test2" : {
    "aliases" : {
      "alias1" : { }
    }
  },
  ".kibana_1" : {
    "aliases" : {
      ".kibana" : { }
    }
  },
  "test1" : {
    "aliases" : { }
  },
  ".kibana_task_manager" : {
    "aliases" : { }
  }
}

4.多个索引添加别名

POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "test1",
        "alias": "alias1"
      }
    },
    {
      "add": {
        "index": "test2",
        "alias": "alias2"
      }
    }
  ]
}
POST /_aliases
{
  "actions": [
    {
      "add": {
        "indices":[ "test1","test2"],        "alias": "alias1"
      }
    }
  ]
}

5.创建过滤器别名

  使用别名应用于所有的search ,count,delete by Query,more like this 操作

  创建过滤器别名,先确定字段在mapping中。

GET my_index

"my_index" : {
    "aliases" : {
      "alias1" : { }
    },
    "mappings" : {
      "properties" : {
        "age" : {
          "type" : "long"
        },
        "created" : {
          "type" : "date"
        },
        "name1" : {
          "type" : "text"
        },
        "title" : {
          "type" : "text"
        }
      }
    }

POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "my_index",
        "alias": "alias3",
        "filter": {"term": {
          "age": "16"
        }}
      }
    }
  ]
}
GET my_index/_alias/*

"my_index" : { "aliases" : { "alias1" : { }, "alias3" : { "filter" : { "term" : { "age" : "16" } } } } }

6. 查询别名

索引名/_alias/别名 

*/_all/glob pattern/ name1,name2

GET my_index/_alias/*
GET my_index/_alias/alias3
GET my_index/_alias/alias3,alias1
GET my_index/_alias/_all

7.滚动索引

滚动索引API接受单个别名和条件列表。

  别名必须指向一个可写的索引,保证滚动请求有效。

两种场景:

  1.别名仅仅指向一个索引,is_write_index参数不配置(默认是true)

  原始索引的别名将滚动到新的索引中,并将别名从原始索引中移除。

  2.别名指向多个索引,在其中一个索引上设置is_write_index为true,用于滚动。

  将原索引的滚动别名的参数is_write_index设置为false,而新创建的索引将滚动别名指向自己,并is_write_index设置为true

PUT /log-00001
{
  "aliases": {
    "logs_write": {}
  }
}

POST /logs_write/_rollover
{
  "conditions": {
    "max_age": "7d",
    "max_docs": 1000,
    "max_size": "5gb"
  }
}
7天或更长时间之前创建
包含1000个或更多文档,
索引的大小至少约为5GB,才会创建新的索引

滚动索引的命名规则是遵循第一个索引的命名规则的,如果想改新的索引如下:

POST /logs_write/_rollover/logs-001
{
   "conditions": {
    "max_age": "7d",
    "max_docs": 1000,
    "max_size": "5gb"
  }
}

猜你喜欢

转载自www.cnblogs.com/qianlanseleiguang/p/11707396.html