我目前正在构建一个可以获得弹性搜索结果列表的系统,但是我在servicemix中遇到一个重复出现的错误(它发生在30-60秒左右),这是因为连接失败了。我如何阻止这种情况发生? 注意运行ElasticSearch 1.7.1 :
public static SearchResponse getElkResponse(InetSocketTransportAddress elkHost, HashMap<String, String> settingsMap, QueryBuilder query, int minTimeRange) {
Settings settings = ImmutableSettings.settingsBuilder()
.put(settingsMap)
.build();
TransportClient client = new TransportClient(settings).addTransportAddress(elkHost);
client.admin().indices().prepareRefresh().execute().actionGet(); //not sure why this is need?
SearchRequestBuilder req = client.prepareSearch()
.setTimeout(TimeValue.timeValueMinutes(1))
.addSort("@timestamp", SortOrder.ASC)
.setQuery(query)
.setPostFilter(FilterBuilders.rangeFilter("@timestamp").from("now-" + minTimeRange + "m").to("now"))
.setSize(100);
SearchResponse res = req.execute().actionGet();
return res;
}
这是我认为导致问题的代码,因为它是与弹性服务器建立连接的代码。
InetSocketTransportAddress通常使用localhost:9300(但是我也在测试错误的地址。
+