elasticsearch-sql JDBC例項
阿新 • • 發佈:2018-11-28
https://github.com/NLPchina/elasticsearch-sql
java連線elasticsearch-sql 測試程式碼
import java.sql.*; import java.util.Properties; import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.ElasticSearchDruidDataSourceFactory; public class Test { public static void main(String[] args) throws Exception { Properties properties = new Properties(); properties.put("url", "jdbc:elasticsearch://192.168.1.181:9300/"); DruidDataSource dds = (DruidDataSource) ElasticSearchDruidDataSourceFactory .createDataSource(properties); dds.setInitialSize(1); Connection connection = dds.getConnection(); String sql2 = "select * FROM t_url limit 10"; PreparedStatement ps = connection.prepareStatement(sql2); ResultSet resultSet = ps.executeQuery(); while (resultSet.next()) { //sql對應輸出 System.out.println(resultSet.getString("info.url") ); } ps.close(); connection.close(); dds.close(); } }