1. 程式人生 > >elasticsearch 別名的操作

elasticsearch 別名的操作

在使用es過程中,如果已存在一個es,需要增加新內容的時候,而且是一個不瞭解之前資料存貯的人進行新增內容時,就很有可能破壞原有的資料,並且es並沒有資料回滾的操作。因此,需要這樣的一個功能,有兩個index,但對查詢只顯示一個index。
強大的es提供了這樣的操作:別名操作。讓你多個的index可以只用一個index查詢。

新增別名

curl -XPOST 'http://localhost:9200/_aliases' -d 
{
    "actions": [
        {"add": {"index": "test1", "alias": "alias1"}}
    ]
}

刪除別名

curl -XPOST 'http://localhost:9200/_aliases' -d 
{
    "actions": [
        {"remove": {"index": "test1", "alias": "alias1"}}
    ]
}

重新命名別名

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
    "actions": [
        {"remove": {"index": "test1", "alias": "alias1"}},
        {"add": {"index":"test1", "
alias": "alias2"}} ] }'

將多個index賦予一個別名

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
    "actions": [
        {"add": {"index": "test1", "alias":"alias1"}},
        {"add": {"index": "test2", "alias":"alias1"}}
    ]
}'