什么是 Elasticsearch-py 等同于别名操作?
What is the Elasticsearch-py equivalent to alias actions?
我正在尝试实施 multiples indices approach using 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")
我不知道如何为第 2 步执行此操作。那么,elasticsearch-dsl(或至少在 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" }}
]
})
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
}
}
}
)
我正在尝试实施 multiples indices approach using 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")
我不知道如何为第 2 步执行此操作。那么,elasticsearch-dsl(或至少在 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" }}
]
})
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
}
}
}
)