Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Elasticsearch-py equivalent to alias actions?

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

1. Create aliases:

PUT /tweets_1/_alias/tweets_search 
PUT /tweets_1/_alias/tweets_index 

2. Change alias when necessary:

POST /_aliases
{
  "actions": [
    { "add":    { "index": "tweets_2", "alias": "tweets_search" }}, 
    { "remove": { "index": "tweets_1", "alias": "tweets_index"  }}, 
    { "add":    { "index": "tweets_2", "alias": "tweets_index"  }}  
  ]
}

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

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

like image 499
Montenegrodr Avatar asked Mar 10 '17 13:03

Montenegrodr


People also ask

What is alias in Elasticsearch?

An alias is a secondary name for a group of data streams or indices. Most Elasticsearch APIs accept an alias in place of a data stream or index name. You can change the data streams or indices of an alias at any time.

What is Elasticsearch PY?

What is ElasticSearch? ElasticSearch (ES) is a distributed and highly available open-source search engine that is built on top of Apache Lucene. It's an open-source which is built in Java thus available for many platforms. You store unstructured data in JSON format which also makes it a NoSQL database.

What is Doc_type Elasticsearch?

Elasticsearch is a powerful open source search and analytics engine that makes data easy to explore. Doc_type is a field in Elasticsearch that allows you to specify the type of document you are indexing. This is useful for when you have multiple types of documents in the same index.


1 Answers

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"  }}  
  ]
})
like image 186
Honza Král Avatar answered Sep 24 '22 03:09

Honza Král