我正在尝试使用elasticsearch-dsl实现倍数索引方法。基本上有两个步骤:
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(而不是dsl)实现步骤1 :
from elasticsearch.client import IndicesClient IndicesClient(client).("tweets_1", "tweets_search") IndicesClient(client).("tweets_1", "tweets_index")
我不知道在第二步该怎么做。那么,elasticsearch-dsl(或至少在elasticsearch-py中)的等效值是什么?
要实现,您需要使用elasticsearch-py:
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" }} ] })