2015-04-20 32 views
0

我將數據存儲到Apache Kafka中。然後我可以使用Apache Storm噴出的數據來處理數據。現在我想將處理的數據導出爲彈性搜索。如何將數據從風暴輸出到彈性搜索?

+1

相關/重複的問題:http://stackoverflow.com/questions/26750821/elasticsearch-storm-integration-methods – frb

回答

0

ElasticSearch提供了可在maven存儲庫中使用的Java客戶端API。

如果您已經實施從kafka拉到風暴, 所有你需要做的是實現一個螺栓發送該日誌的索引請求彈性搜索。

在這裏,我在傳統的拓撲視角。

例如,在您的prepare方法實現中,您可以像這樣創建一個傳輸客戶端。

Client client = new TransportClient() 
    .addTransportAddress(new InetSocketTransportAddress("host1", 9300)) 
    .addTransportAddress(new InetSocketTransportAddress("host2", 9300)); 

而在你的執行方法實現中,你發送這樣的索引請求。

String json = "{" + 
    "\"user\":\"kimchy\"," + 
    "\"postDate\":\"2013-01-30\"," + 
    "\"message\":\"trying out Elasticsearch\"" + 
"}"; 

IndexResponse response = client.prepareIndex("twitter", "tweet") 
    .setSource(json) 
    .execute() 
    .actionGet(); 

欲瞭解更多信息,請參閱http://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html