我正在尝试使用multiples indices实施elasticsearch-dsl方法。基本上有两个步骤:
1。创建别名:
sys.exit()
2。必要时更改别名:
PUT /tweets_1/_alias/tweets_search
PUT /tweets_1/_alias/tweets_index
我只能使用elasticsearch-py(而不是dsl)实现第1步:
POST /_aliases
{
"actions": [
{ "add": { "index": "tweets_2", "alias": "tweets_search" }},
{ "remove": { "index": "tweets_1", "alias": "tweets_index" }},
{ "add": { "index": "tweets_2", "alias": "tweets_index" }}
]
}
我不知道如何为第2步执行此操作。那么,elasticsearch-dsl(或至少在elasticsearch-py中)的等价物是什么?
答案 0 :(得分:11)
要实现您需要使用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" }}
]
})
答案 1 :(得分:0)
index_list_for_realias = [...]
aliases_list_to_realias = [...]
for i in index_list_for_realias:
print(i)
for j in aliases_list_to_realias:
es.indices.put_alias(index=i, name="logstash5-uni-" + j, body={
"filter": {
"term": {
"uni": j
}
}
}
)