Search timing problem, I suppose

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"}