# Problem with Java API callbacks

**URL:** <https://discuss.elastic.co/t/problem-with-java-api-callbacks/3009>\
**Category:** Elasticsearch\
**Created:** [June 10, 2010, 12:59pm UTC](https://discuss.elastic.co/t/problem-with-java-api-callbacks/3009 "2010-06-10T12:59:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lenak](https://avatars.discourse-cdn.com/v4/letter/l/96bed5/32.png) [@Lenak](https://discuss.elastic.co/u/Lenak)\
**Post date:** [June 10, 2010, 12:59pm UTC](https://discuss.elastic.co/t/problem-with-java-api-callbacks/3009/1 "2010-06-10T12:59:26Z")

</div>

Hi,

I found out that when using the Java API on index, i.e:  
client.index(..., new ActionListener()...)

then my callback's onSuccess() method is called BEFORE the document is accessible in the index. I search for the document immediately after onSuccess() has been called, and receive an older version than what was just indexed.

Any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [June 10, 2010, 2:23pm UTC](https://discuss.elastic.co/t/problem-with-java-api-callbacks/3009/2 "2010-06-10T14:23:30Z")

</div>

Hi,

You mean you search for the document using the same client instance which is  
used to index the document in the onResponse() method of ActionListener?

Something like:  
Client myclient = new NodeClient();  
myclient.index( ..., new ActionListener() { onResponse() { myclient.search()  
} } )

Regards,  
Lukas

On Thu, Jun 10, 2010 at 2:59 PM, Lenak [lenakovganov@gmail.com](mailto:lenakovganov@gmail.com) wrote:

> Hi,
> 
> I found out that when using the Java API on index, i.e:  
> client.index(..., new ActionListener()...)
> 
> then my callback's onSuccess() method is called BEFORE the document is  
> accessible in the index. I search for the document immediately after  
> onSuccess() has been called, and receive an older version than what was  
> just  
> indexed.
> 
> Any ideas?
> 
> Thanks!
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Java-API-callbacks-tp885464p885464.html](http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Java-API-callbacks-tp885464p885464.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Lenak](https://avatars.discourse-cdn.com/v4/letter/l/96bed5/32.png) [@Lenak](https://discuss.elastic.co/u/Lenak)\
**Post date:** [June 10, 2010, 2:42pm UTC](https://discuss.elastic.co/t/problem-with-java-api-callbacks/3009/3 "2010-06-10T14:42:21Z")

</div>

yes, exactly like you described.  
You think there a problem working this way?

On Thu, Jun 10, 2010 at 5:23 PM, Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com) wrote:

> Hi,
> 
> You mean you search for the document using the same client instance which  
> is used to index the document in the onResponse() method of ActionListener?
> 
> Something like:  
> Client myclient = new NodeClient();  
> myclient.index( ..., new ActionListener() { onResponse() {  
> myclient.search() } } )
> 
> Regards,  
> Lukas
> 
> On Thu, Jun 10, 2010 at 2:59 PM, Lenak [lenakovganov@gmail.com](mailto:lenakovganov@gmail.com) wrote:
> 
> > Hi,
> > 
> > I found out that when using the Java API on index, i.e:  
> > client.index(..., new ActionListener()...)
> > 
> > then my callback's onSuccess() method is called BEFORE the document is  
> > accessible in the index. I search for the document immediately after  
> > onSuccess() has been called, and receive an older version than what was  
> > just  
> > indexed.
> > 
> > Any ideas?
> > 
> > Thanks!
> > 
> > --  
> > View this message in context:  
> > [http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Java-API-callbacks-tp885464p885464.html](http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Java-API-callbacks-tp885464p885464.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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:** [June 10, 2010, 7:39pm UTC](https://discuss.elastic.co/t/problem-with-java-api-callbacks/3009/4 "2010-06-10T19:39:31Z")

</div>

You can certainly work like that. Elasticsearch provides near real time  
search support, this means that search / get requests will only "see"  
indexed documents after an interval (which can be configured). There is an  
API called refresh that makes all indexable documented visible for search.

Note, refresh is not a lightweight operation, and can affect indexing  
performance.

-shay.banon

On Thu, Jun 10, 2010 at 5:42 PM, Lena Kovganov [lenakovganov@gmail.com](mailto:lenakovganov@gmail.com)wrote:

> yes, exactly like you described.  
> You think there a problem working this way?
> 
> On Thu, Jun 10, 2010 at 5:23 PM, Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com)wrote:
> 
> > Hi,
> > 
> > You mean you search for the document using the same client instance which  
> > is used to index the document in the onResponse() method of ActionListener?
> > 
> > Something like:  
> > Client myclient = new NodeClient();  
> > myclient.index( ..., new ActionListener() { onResponse() {  
> > myclient.search() } } )
> > 
> > Regards,  
> > Lukas
> > 
> > On Thu, Jun 10, 2010 at 2:59 PM, Lenak [lenakovganov@gmail.com](mailto:lenakovganov@gmail.com) wrote:
> > 
> > > Hi,
> > > 
> > > I found out that when using the Java API on index, i.e:  
> > > client.index(..., new ActionListener()...)
> > > 
> > > then my callback's onSuccess() method is called BEFORE the document is  
> > > accessible in the index. I search for the document immediately after  
> > > onSuccess() has been called, and receive an older version than what was  
> > > just  
> > > indexed.
> > > 
> > > Any ideas?
> > > 
> > > Thanks!
> > > 
> > > --  
> > > View this message in context:  
> > > [http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Java-API-callbacks-tp885464p885464.html](http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Java-API-callbacks-tp885464p885464.html)  
> > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![amitzur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amitzur/32/3333_2.png) [@amitzur](https://discuss.elastic.co/u/amitzur)\
**Post date:** [June 13, 2010, 6:26am UTC](https://discuss.elastic.co/t/problem-with-java-api-callbacks/3009/5 "2010-06-13T06:26:25Z")

</div>

[This is the original poster]  
**1.** The thing is I wish to know the exact point in runtime when the document can be seen in index. That's why I use the ActionListener.  
The reason for this is that pending index requests are dependent on the current index operation to finish (and for the document to be accessible).

**2.** where is that interval configured ?

Thanks,  
Amit

---

<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, 4:23am UTC](https://discuss.elastic.co/t/problem-with-java-api-callbacks/3009/6 "2017-07-06T04:23:21Z")

</div>


