# Working with aliases using Java API

**URL:** https://discuss.elastic.co/t/working-with-aliases-using-java-api/5294
**Category:** Elasticsearch
**Created:** [September 1, 2011, 9:01am UTC](https://discuss.elastic.co/t/working-with-aliases-using-java-api/5294 "2011-09-01T09:01:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Andrew\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_2/32/3126_2.png) [@Andrew\_2](https://discuss.elastic.co/u/Andrew_2)
#### Post date: [September 1, 2011, 9:01am UTC](https://discuss.elastic.co/t/working-with-aliases-using-java-api/5294/1 "2011-09-01T09:01:32Z")

</div>

Hi everybody,

like many people here I am planing to use ES and currently I am  
preparing a kind of a proof of concept. So far I can tell that ES is a  
briliant piece of software and Shay is doing an incredible job  
developing it.

Everything went smooth so far but now I am kind of lost 🙂

I am planing to use ES in the following scenario. From a customer I  
have a data feed that contains all the data I need to index. I have no  
information which items have changed or were added or deleted. That  
means that I will periodically do a full reindex. It is not a problem  
because we are talking about ~200,000 documents that have ~50 MB in  
total. This way is also the the easiest way for the client to export  
their data.

From my point of view the right way is to do every reindex into a  
newly created index and use an alias for client applications to  
connect to the right one. That means that after a successful reindex I  
need to change the alias and I can delete the old index.

And my problem is that I have no idea how to work with aliases using  
the Java API 🙂 I have found a thread here where Shay explained how to  
get a list of existing aliases. I can do that, so I know the name of  
the old index I can delete eventually. But I don't know how to alter  
the alias using the Java API. Could somebody please help me? I expect  
that I will end up having to prepare and send the JSON request by hand  
(so maybe I am looking for a way how to send an arbitrary request  
using the Java API). That is fine by me. I just need a little help  
where to look 🙂 Thanks!

A.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [September 1, 2011, 10:30am UTC](https://discuss.elastic.co/t/working-with-aliases-using-java-api/5294/2 "2011-09-01T10:30:02Z")

</div>

Heya, here is a sample:

client.admin().indices().prepareAliases().addAlias("my\_index",  
"my\_alias").removeAlias("my\_old\_index", "my\_alias").execute().actionGet();

On Thu, Sep 1, 2011 at 12:01 PM, Andrew [ondrej.nespor@gmail.com](mailto:ondrej.nespor@gmail.com) wrote:

> Hi everybody,
> 
> like many people here I am planing to use ES and currently I am  
> preparing a kind of a proof of concept. So far I can tell that ES is a  
> briliant piece of software and Shay is doing an incredible job  
> developing it.
> 
> Everything went smooth so far but now I am kind of lost 🙂
> 
> I am planing to use ES in the following scenario. From a customer I  
> have a data feed that contains all the data I need to index. I have no  
> information which items have changed or were added or deleted. That  
> means that I will periodically do a full reindex. It is not a problem  
> because we are talking about ~200,000 documents that have ~50 MB in  
> total. This way is also the the easiest way for the client to export  
> their data.
> 
> From my point of view the right way is to do every reindex into a  
> newly created index and use an alias for client applications to  
> connect to the right one. That means that after a successful reindex I  
> need to change the alias and I can delete the old index.
> 
> And my problem is that I have no idea how to work with aliases using  
> the Java API 🙂 I have found a thread here where Shay explained how to  
> get a list of existing aliases. I can do that, so I know the name of  
> the old index I can delete eventually. But I don't know how to alter  
> the alias using the Java API. Could somebody please help me? I expect  
> that I will end up having to prepare and send the JSON request by hand  
> (so maybe I am looking for a way how to send an arbitrary request  
> using the Java API). That is fine by me. I just need a little help  
> where to look 🙂 Thanks!
> 
> A.

---

<div class="post-metadata">

### Author: ![Andrew\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_2/32/3126_2.png) [@Andrew\_2](https://discuss.elastic.co/u/Andrew_2)
#### Post date: [September 1, 2011, 2:44pm UTC](https://discuss.elastic.co/t/working-with-aliases-using-java-api/5294/3 "2011-09-01T14:44:08Z")

</div>

Hi,

thanks! It is way easier than I expected 🙂

A.

On 1 zář, 12:30, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Heya, here is a sample:
> 
> client.admin().indices().prepareAliases().addAlias("my\_index",  
> "my\_alias").removeAlias("my\_old\_index", "my\_alias").execute().actionGet();
> 
> On Thu, Sep 1, 2011 at 12:01 PM, Andrew [ondrej.nes...@gmail.com](mailto:ondrej.nes...@gmail.com) wrote:
> 
> > Hi everybody,
> 
> > like many people here I am planing to use ES and currently I am  
> > preparing a kind of a proof of concept. So far I can tell that ES is a  
> > briliant piece of software and Shay is doing an incredible job  
> > developing it.
> 
> > Everything went smooth so far but now I am kind of lost 🙂
> 
> > I am planing to use ES in the following scenario. From a customer I  
> > have a data feed that contains all the data I need to index. I have no  
> > information which items have changed or were added or deleted. That  
> > means that I will periodically do a full reindex. It is not a problem  
> > because we are talking about ~200,000 documents that have ~50 MB in  
> > total. This way is also the the easiest way for the client to export  
> > their data.
> 
> > From my point of view the right way is to do every reindex into a  
> > newly created index and use an alias for client applications to  
> > connect to the right one. That means that after a successful reindex I  
> > need to change the alias and I can delete the old index.
> 
> > And my problem is that I have no idea how to work with aliases using  
> > the Java API 🙂 I have found a thread here where Shay explained how to  
> > get a list of existing aliases. I can do that, so I know the name of  
> > the old index I can delete eventually. But I don't know how to alter  
> > the alias using the Java API. Could somebody please help me? I expect  
> > that I will end up having to prepare and send the JSON request by hand  
> > (so maybe I am looking for a way how to send an arbitrary request  
> > using the Java API). That is fine by me. I just need a little help  
> > where to look 🙂 Thanks!
> 
> > A.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 3:55am UTC](https://discuss.elastic.co/t/working-with-aliases-using-java-api/5294/4 "2017-07-06T03:55:21Z")

</div>


