采坑
这节我们来说下如何使用sql来查询es,网上很多使用 NLPChina提供的elasticsearch-sql包,比如gitlab上给出的案例
public void testJDBC() throws Exception {
Properties properties = new Properties();
properties.put("url", "jdbc:elasticsearch://127.0.0.1:9300/" + TestsConstants.TEST_INDEX);
DruidDataSource dds = (DruidDataSource) ElasticSearchDruidDataSourceFactory.createDataSource(properties);
Connection connection = dds.getConnection();
PreparedStatement ps = connection.prepareStatement("SELECT gender,lastname,age from " + TestsConstants.TEST_INDEX + " where lastname='Heath'");
ResultSet resultSet = ps.executeQuery();
List<String> result = new ArrayList<String>();
while (resultSet.next()) {
System.out.println(resultSet.getString("lastname") + "," + resultSet.getInt("age") + "," + resultSet.getString("gender"))

本文分享了使用SQL查询Elasticsearch的实践经验,包括解决版本兼容性问题、依赖冲突及授权许可难题,最终实现了高效的数据检索。
最低0.47元/天 解锁文章
3万+

被折叠的 条评论
为什么被折叠?



