2017-03-10 61 views
3

我正在嘗試使用elasticsearch-dsl執行multiples indices的方法。基本上有兩個步驟:什麼是Elasticsearch-py等效於別名操作?

1.創建別名:

PUT /tweets_1/_alias/tweets_search 
PUT /tweets_1/_alias/tweets_index 

2.更改別名必要時:

POST /_aliases 
{ 
    "actions": [ 
    { "add": { "index": "tweets_2", "alias": "tweets_search" }}, 
    { "remove": { "index": "tweets_1", "alias": "tweets_index" }}, 
    { "add": { "index": "tweets_2", "alias": "tweets_index" }} 
    ] 
} 

我只能實現使用elasticsearch-py步驟1(不是dsl):

from elasticsearch.client import IndicesClient 
IndicesClient(client).("tweets_1", "tweets_search") 
IndicesClient(client).("tweets_1", "tweets_index") 

我不知道如何做第2步。那麼,在elasticsearch-dsl(或者至少在elasticsearch-py)中等價呢?

回答

6

要實現,你需要使用elasticsearch-py

from elasticsearch import Elasticsearch 
es = Elasticsearch() 

# use es.indices instead of instantiating IndicesClient 
es.indices.put_alias(index='tweets_1', name='tweets_search') 
es.indices.put_alias(index='tweets_1', name='tweets_index') 

es.indices.update_aliases({ 
    "actions": [ 
    { "add": { "index": "tweets_2", "alias": "tweets_search" }}, 
    { "remove": { "index": "tweets_1", "alias": "tweets_index" }}, 
    { "add": { "index": "tweets_2", "alias": "tweets_index" }} 
    ] 
}) 
相關問題