# Search timing problem, I suppose

**URL:** <https://discuss.elastic.co/t/search-timing-problem-i-suppose/7981>\
**Category:** Elasticsearch\
**Created:** [June 5, 2012, 2:53pm UTC](https://discuss.elastic.co/t/search-timing-problem-i-suppose/7981 "2012-06-05T14:53:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tullio0106](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tullio0106](https://discuss.elastic.co/u/tullio0106)\
**Post date:** [June 5, 2012, 2:53pm UTC](https://discuss.elastic.co/t/search-timing-problem-i-suppose/7981/1 "2012-06-05T14:53:11Z")

</div>

I've a very simple test program I show below. Sometime it will find correct results ans sometime it doesn't.  
Trying to understand what happend I noticed that, debugging my program it worked every time.  
Looking console informations I noticed the following message

2012-06-05 16:39:52,468 INFO [org.elasticsearch.gateway] - [Terraxia] recovered [1] indices into cluster\_state

which seems to be asincrhonous and the time where it comes out seems to influence the result.  
I suspect a timing problem in node startup but I didn't find any way to wait for the end of all underlying operations.  
Could someone help ?  
Tks Tullio

public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException {  
Node node = NodeBuilder.nodeBuilder().node();  
Client c = node.client();  
ObjectMapper mapper = new ObjectMapper();  
HashMap\<String,Object\> mappa = new HashMap\<String,Object\>();  
mappa.put("user", "Tullio"); mappa.put("data", new Date());  
mappa.put("message", "La vispa teresina avea tra");  
long inizio = new Date().getTime();  
StringWriter sw = new StringWriter();  
mapper.writeValue(sw, mappa);  
String json = sw.getBuffer().toString();  
System.out.println(json);  
IndexResponse irb = c.prepareIndex("test","test","2").setSource(json).execute().actionGet();  
long gap = new Date().getTime() - inizio; System.out.println("millis "+gap);  
SearchResponse response = c.prepareSearch("test") .setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery(termQuery("message", "teresina")) .setFrom(0).setSize(60).setExplain(true) .execute() .actionGet();  
SearchHits sh = response.getHits();  
long numero = sh.getTotalHits();  
System.out.println("Trovati "+numero);  
}

The printed Json message  
{"message":"La vispa teresina avea tra","data":1338907189464,"user":"Tullio"}

---

<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:25am UTC](https://discuss.elastic.co/t/search-timing-problem-i-suppose/7981/2 "2017-07-06T03:25:36Z")

</div>

Closed on July 6, 2017, 3:25am UTC


