# Setting the refresh interval from Java API

**URL:** <https://discuss.elastic.co/t/setting-the-refresh-interval-from-java-api/11409>\
**Category:** Elasticsearch\
**Created:** [April 2, 2013, 2:00am UTC](https://discuss.elastic.co/t/setting-the-refresh-interval-from-java-api/11409 "2013-04-02T02:00:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Chambers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matt_chambers/32/607_2.png) [@Matt\_Chambers](https://discuss.elastic.co/u/Matt_Chambers)\
**Post date:** [April 2, 2013, 2:00am UTC](https://discuss.elastic.co/t/setting-the-refresh-interval-from-java-api/11409/1 "2013-04-02T02:00:33Z")

</div>

Anyone have an example on how to do this? Its easy with Curl but I'm  
embedding this bulk indexing operation into my server.

-Matt

--  
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:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 2, 2013, 6:23am UTC](https://discuss.elastic.co/t/setting-the-refresh-interval-from-java-api/11409/2 "2013-04-02T06:23:07Z")

</div>

Hey,

there are several possibilities. If you want to do it manually you can  
issue a refresh request (possible if you have an IndicesAdminClient). If  
you want to change the settings, you can fire an updateSettingsRequest for  
the index.

// you need a settings builder for the changed settings as additional  
parameter here  
client.admin().indices().prepareUpdateSettings(...)  
node.client().admin().indices().prepareRefresh("yourindex")

Hope this helps...

--Alex

On Tue, Apr 2, 2013 at 4:00 AM, Matt Chambers [yougotrooted@gmail.com](mailto:yougotrooted@gmail.com)wrote:

> Anyone have an example on how to do this? Its easy with Curl but I'm  
> embedding this bulk indexing operation into my server.
> 
> -Matt
> 
> --  
> 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).

--  
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:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [April 2, 2013, 8:17pm UTC](https://discuss.elastic.co/t/setting-the-refresh-interval-from-java-api/11409/3 "2013-04-02T20:17:34Z")

</div>

Here's the internal snippet that I use to change one of two settings for an  
existing index: The number of replicas, and the index refresh rate. There's  
an enum defined with the two enumerated setting values that I currently  
need to support in the Java code. The index is simply a Java String name of  
an index. The index typically must exist for me: I currently prefer to  
create an index with all settings and mappings instead of let the defaults  
take over. But that's just me.

Map\<String, String\> settings\_map = new HashMap\<String, String\>();  
switch (setting)  
{  
case NUMBER\_OF\_REPLICAS:  
settings\_map.put("index.number\_of\_replicas", value);  
break;  
case REFRESH\_INTERVAL:  
settings\_map.put("index.refresh\_interval", value);  
break;  
default:  
throw new YourOwnException("Unsupported setting: "  
+ setting + " with value " + value);  
}

try  
{  
Settings settings = ImmutableSettings.settingsBuilder().put(settings\_map)  
.build();

UpdateSettingsRequestBuilder usrb = client.admin().indices()  
.prepareUpdateSettings();  
usrb.setIndices(index);  
usrb.setSettings(settings);  
usrb.execute().actionGet();  
}  
catch (ElasticSearchException e)  
{  
// TODO: Throw your own exception here if you wish  
}

On Monday, April 1, 2013 10:00:33 PM UTC-4, Matt Chambers wrote:

> Anyone have an example on how to do this? Its easy with Curl but I'm  
> embedding this bulk indexing operation into my server.
> 
> -Matt

--  
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:43am UTC](https://discuss.elastic.co/t/setting-the-refresh-interval-from-java-api/11409/4 "2017-07-06T02:43:13Z")

</div>


