# Index updating/ refreshing for parallel applications

**URL:** <https://discuss.elastic.co/t/index-updating-refreshing-for-parallel-applications/11628>\
**Category:** Elasticsearch\
**Created:** [April 18, 2013, 9:47am UTC](https://discuss.elastic.co/t/index-updating-refreshing-for-parallel-applications/11628 "2013-04-18T09:47:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![K\_B\_2](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@K\_B\_2](https://discuss.elastic.co/u/K_B_2)\
**Post date:** [April 18, 2013, 9:47am UTC](https://discuss.elastic.co/t/index-updating-refreshing-for-parallel-applications/11628/1 "2013-04-18T09:47:05Z")

</div>

Hello,

we use elasticsearch now since version .11 and we really like it (currently  
on .19.11). However, one thing thats a big problem for us is to update the  
index while it is still queried by other requests.

We currently do a index-shift using alias in a java singleton e.g.:

private static String searchindex = "searchindex"; \<- is only alias  
private static String indexingIndexA = "indexingindex\_a"; \<- is a real index  
private static String indexingIndexB = "indexingindex\_b"; \<- is a real index

String workingIndex;  
String currentActiveSearchIndex;  
if (singletonBean.getAliasTo().equals(indexingIndexA)) {  
singletonBean.setAliasTo(indexingIndexB);  
workingIndex = indexingIndexB;  
currentActiveSearchIndex = indexingIndexA;  
} else {  
singletonBean.setAliasTo(indexingIndexA);  
workingIndex = indexingIndexA;  
currentActiveSearchIndex = indexingIndexB;  
}

```
    try {
        client.admin().indices().delete(new 

```

DeleteIndexRequest(workingIndex)).actionGet();  
} catch (Exception e) {  
logger.info(e.getMessage());  
}

... do index work ....

client.admin().indices().refresh(new RefreshRequest(workingIndex));  
client.admin().indices().aliases(new  
IndicesAliasesRequest().removeAlias(currentActiveSearchIndex,  
searchindex).addAlias(workingIndex, searchindex));

This runs quite well as long as its the only one that works on it. Now we  
wanted to call ES from a second and third application and get the index  
refreshed, however when in same time a request is done to the same index it  
will lead to trouble as the alias swap can occure right in the middle.

How can we upgrade the whole index from any app without breaking the  
ongoing requests of the other ones?  
In solr there exists a "swap(index, index)" command where 2 indexes get  
swapped in way that all requests prior to time x get done by first and  
after that by second index, meaning that solr will handle the parallel  
request problems.

Any help would be really appreciated.

Best Regards,

KB

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 18, 2013, 10:32pm UTC](https://discuss.elastic.co/t/index-updating-refreshing-for-parallel-applications/11628/2 "2013-04-18T22:32:48Z")

</div>

Equivalent of swap(index, index) in elasticsearch would be this:

curl -XPOST '[http://localhost:9200/\_aliases](http://localhost:9200/_aliases)' -d '  
{  
"actions" : [  
{ "remove" : { "index" : "indexingindex\_a", "alias" :  
"indexing\_index" } },  
{ "remove" : { "index" : "indexingindex\_b", "alias" :  
"searching\_index" } },  
{ "add" : { "index" : "indexingindex\_a", "alias" :  
"searching\_index" } },  
{ "add" : { "index" : "indexingindex\_b", "alias" : "indexing\_index"  
} }  
]  
}'

I am not sure how this (or solr's swap) would help you though. Even if you  
will somehow make refresh with swap an atomic operation, you will still  
have problems If one application will refresh and swap indices while  
another applications is trying to index. It sounds like you need some sort  
of cluster-wide lock that all other applications would observe. Maybe you  
can create a special index with a record in it that would contain the id of  
the process that currently "owns" the working index.

On Thursday, April 18, 2013 5:47:05 AM UTC-4, K.B. wrote:

> Hello,
> 
> we use elasticsearch now since version .11 and we really like it  
> (currently on .19.11). However, one thing thats a big problem for us is to  
> update the index while it is still queried by other requests.
> 
> We currently do a index-shift using alias in a java singleton e.g.:
> 
> private static String searchindex = "searchindex"; \<- is only alias  
> private static String indexingIndexA = "indexingindex\_a"; \<- is a real  
> index  
> private static String indexingIndexB = "indexingindex\_b"; \<- is a real  
> index
> 
> String workingIndex;  
> String currentActiveSearchIndex;  
> if (singletonBean.getAliasTo().equals(indexingIndexA)) {  
> singletonBean.setAliasTo(indexingIndexB);  
> workingIndex = indexingIndexB;  
> currentActiveSearchIndex = indexingIndexA;  
> } else {  
> singletonBean.setAliasTo(indexingIndexA);  
> workingIndex = indexingIndexA;  
> currentActiveSearchIndex = indexingIndexB;  
> }
> 
> ```
> try {
> client.admin().indices().delete(new 
> 
> ```
> 
> DeleteIndexRequest(workingIndex)).actionGet();  
> } catch (Exception e) {  
> logger.info(e.getMessage());  
> }
> 
> ... do index work ....
> 
> client.admin().indices().refresh(new RefreshRequest(workingIndex));  
> client.admin().indices().aliases(new  
> IndicesAliasesRequest().removeAlias(currentActiveSearchIndex,  
> searchindex).addAlias(workingIndex, searchindex));
> 
> This runs quite well as long as its the only one that works on it. Now we  
> wanted to call ES from a second and third application and get the index  
> refreshed, however when in same time a request is done to the same index it  
> will lead to trouble as the alias swap can occure right in the middle.
> 
> How can we upgrade the whole index from any app without breaking the  
> ongoing requests of the other ones?  
> In solr there exists a "swap(index, index)" command where 2 indexes get  
> swapped in way that all requests prior to time x get done by first and  
> after that by second index, meaning that solr will handle the parallel  
> request problems.
> 
> Any help would be really appreciated.
> 
> Best Regards,
> 
> KB

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:40am UTC](https://discuss.elastic.co/t/index-updating-refreshing-for-parallel-applications/11628/3 "2017-07-06T02:40:34Z")

</div>


