# Java api : bulk refresh

**URL:** <https://discuss.elastic.co/t/java-api-bulk-refresh/3831>\
**Category:** Elasticsearch\
**Created:** [January 26, 2011, 9:47am UTC](https://discuss.elastic.co/t/java-api-bulk-refresh/3831 "2011-01-26T09:47:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nel\_taurisson](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@nel\_taurisson](https://discuss.elastic.co/u/nel_taurisson)\
**Post date:** [January 26, 2011, 9:47am UTC](https://discuss.elastic.co/t/java-api-bulk-refresh/3831/1 "2011-01-26T09:47:28Z")

</div>

Hi,

This is my first post here, so first thanks a lot for the wonderfull  
framework.

I'm using java api and I'm wondering if the setRefresh( true ) method  
on a BulkRequestBuilder should lead for wainting for all the bulk's  
operation to be searchable (as I would expect as this is the behaviour  
with an IndexRequestBuilder). In fact, in the following code, it  
doesn't, but as I'm very new to es, maybe I'm doing something wrong :

BulkRequestBuilder bulk = this.client.prepareBulk() ;  
bulk.setRefresh( true ) ;

bulk.add( this.client.prepareIndex()  
.setRefresh( true )  
.setIndex( "index1")  
.setType( "doc" )  
.setId( "1" )  
.setSource( "{"name":"toto"}" ) ) ;  
bulk.add( this.client.prepareIndex()  
.setRefresh( true )  
.setIndex( "index1")  
.setType( "doc" )  
.setId( "2" )  
.setSource( "{"name":"titi"}" ) ) ;

BulkResponse response = bulk.execute().actionGet();

GetResponse get = this.client.prepareGet()  
.setIndex( "index1" )  
.setType( "doc" )  
.setId( "1" ).execute().actionGet();

assertTrue( get.exists() ) ; // which fails

Thanks for any help

Nel

---

<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:** [January 26, 2011, 10:03am UTC](https://discuss.elastic.co/t/java-api-bulk-refresh/3831/2 "2011-01-26T10:03:14Z")

</div>

I fixed a bug that the refresh flag was not being taken into account in master (upcoming 0.15 version). I think you hit it 🙂  
On Wednesday, January 26, 2011 at 11:47 AM, nel.taurisson wrote:

> Hi,
> 
> This is my first post here, so first thanks a lot for the wonderfull  
> framework.
> 
> I'm using java api and I'm wondering if the setRefresh( true ) method  
> on a BulkRequestBuilder should lead for wainting for all the bulk's  
> operation to be searchable (as I would expect as this is the behaviour  
> with an IndexRequestBuilder). In fact, in the following code, it  
> doesn't, but as I'm very new to es, maybe I'm doing something wrong :
> 
> BulkRequestBuilder bulk = this.client.prepareBulk() ;  
> bulk.setRefresh( true ) ;
> 
> bulk.add( this.client.prepareIndex()  
> .setRefresh( true )  
> .setIndex( "index1")  
> .setType( "doc" )  
> .setId( "1" )  
> .setSource( "{"name":"toto"}" ) ) ;  
> bulk.add( this.client.prepareIndex()  
> .setRefresh( true )  
> .setIndex( "index1")  
> .setType( "doc" )  
> .setId( "2" )  
> .setSource( "{"name":"titi"}" ) ) ;
> 
> BulkResponse response = bulk.execute().actionGet();
> 
> GetResponse get = this.client.prepareGet()  
> .setIndex( "index1" )  
> .setType( "doc" )  
> .setId( "1" ).execute().actionGet();
> 
> assertTrue( get.exists() ) ; // which fails
> 
> Thanks for any help
> 
> Nel

---

<div class="post-metadata">

**Author:** ![nel\_taurisson](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@nel\_taurisson](https://discuss.elastic.co/u/nel_taurisson)\
**Post date:** [January 26, 2011, 10:05am UTC](https://discuss.elastic.co/t/java-api-bulk-refresh/3831/3 "2011-01-26T10:05:31Z")

</div>

great !

2011/1/26 Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com):

> I fixed a bug that the refresh flag was not being taken into account in  
> master (upcoming 0.15 version). I think you hit it 🙂
> 
> On Wednesday, January 26, 2011 at 11:47 AM, nel.taurisson wrote:
> 
> Hi,
> 
> This is my first post here, so first thanks a lot for the wonderfull  
> framework.
> 
> I'm using java api and I'm wondering if the setRefresh( true ) method  
> on a BulkRequestBuilder should lead for wainting for all the bulk's  
> operation to be searchable (as I would expect as this is the behaviour  
> with an IndexRequestBuilder). In fact, in the following code, it  
> doesn't, but as I'm very new to es, maybe I'm doing something wrong :
> 
> BulkRequestBuilder bulk = this.client.prepareBulk() ;  
> bulk.setRefresh( true ) ;
> 
> bulk.add( this.client.prepareIndex()  
> .setRefresh( true )  
> .setIndex( "index1")  
> .setType( "doc" )  
> .setId( "1" )  
> .setSource( "{"name":"toto"}" ) ) ;  
> bulk.add( this.client.prepareIndex()  
> .setRefresh( true )  
> .setIndex( "index1")  
> .setType( "doc" )  
> .setId( "2" )  
> .setSource( "{"name":"titi"}" ) ) ;
> 
> BulkResponse response = bulk.execute().actionGet();
> 
> GetResponse get = this.client.prepareGet()  
> .setIndex( "index1" )  
> .setType( "doc" )  
> .setId( "1" ).execute().actionGet();
> 
> assertTrue( get.exists() ) ; // which fails
> 
> Thanks for any help
> 
> Nel

---

<div class="post-metadata">

**Author:** ![rauanmaemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauanmaemirov/32/4700_2.png) [@rauanmaemirov](https://discuss.elastic.co/u/rauanmaemirov)\
**Post date:** [September 11, 2015, 10:52am UTC](https://discuss.elastic.co/t/java-api-bulk-refresh/3831/4 "2015-09-11T10:52:40Z")

</div>

Is it fixed in 1.7.1?  
With `"refresh_interval": "-1"`, I'm continuously bulking with `.refresh(true)` on an entire bulk and I'm not seeing up to date counts on my index. After finishing all my bulks I manually send `_refresh` request and only then I see the valid hits count.

---

<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 5, 2017, 11:50pm UTC](https://discuss.elastic.co/t/java-api-bulk-refresh/3831/5 "2017-07-05T23:50:46Z")

</div>


