什么是Elasticsearch-py等效于别名操作? [英] What is the Elasticsearch-py equivalent to alias actions?

查看:113
本文介绍了什么是Elasticsearch-py等效于别名操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实施 multiples使用 elasticsearch-dsl 的索引方法。基本上有两个步骤:

I am trying to implement multiples indices approach using elasticsearch-dsl. There are basically two steps:

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):

I could only implement the step 1 using elasticsearch-py (not the dsl):

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

我不知道如何执行步骤2。因此,elasticsearch-dsl(或至少在elasticsearch-py中)等效)?

I have no clue how to do that for step 2. So, what would be the equivalent in elasticsearch-dsl (or at least in elasticsearch-py)?

推荐答案

要实现该功能,您需要使用 elasticsearch-py

To implement that you need to use 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"  }}  
  ]
})

这篇关于什么是Elasticsearch-py等效于别名操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆