elasticsearch-sql JDBC实例

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();
	}
}

 

你可能感兴趣的:(elasticsearch-sql JDBC实例)