【发布时间】:2016-02-27 03:19:10
【问题描述】:
我想在 Elastic-Search 中使用 routing-field。
但我找不到任何 Java API 来启用它。
我经历过link 1 和link 2,但似乎都没有解决这个问题。
我的代码:
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
this.collector = collector;
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", elasticSearchCluster).build();
this.client = new TransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(esHost, esPort));
}
public void execute(Tuple tuple) {
try {
String document = tuple.toString();
byte[] byteBuffer = document.getBytes();
IndexResponse response = this.client.prepareIndex(indexName, type, id)
.setSource(byteBuffer).execute().actionGet();
} catch (Exception e) {
e.printStackTrace();
}
collector.ack(tuple);
}
请注意,我在这里使用的是 TransportClient,因为似乎没有将 Node-Client 与 Storm 一起使用的好方法,但问题与此无关。如果有使用 Node-Client 路由的方法,请提出建议,否则 TransportClient 的路由也会有很大帮助。
【问题讨论】:
标签: elasticsearch apache-storm