Mon*_*odr 7 python elasticsearch elasticsearch-dsl elasticsearch-py
我正在尝试使用elasticsearch-dsl实现多重索引方法.基本上有两个步骤:
1.创建别名:
PUT /tweets_1/_alias/tweets_search
PUT /tweets_1/_alias/tweets_index
Run Code Online (Sandbox Code Playgroud)
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" }}
]
}
Run Code Online (Sandbox Code Playgroud)
我只能使用elasticsearch-py(而不是dsl)实现第1步:
from elasticsearch.client import IndicesClient
IndicesClient(client).("tweets_1", "tweets_search")
IndicesClient(client).("tweets_1", "tweets_index")
Run Code Online (Sandbox Code Playgroud)
我不知道如何为第2步做到这一点.那么,elasticsearch-dsl(或者至少在elasticsearch-py中)的等价物是什么?
Hon*_*rál 13
要实现您需要使用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" }}
]
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3169 次 |
| 最近记录: |