利用sql查询es
import org.junit.Assert;
import org.junit.Test;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.SimpleDateFormat;
public class JDBCTests {
@Test
public void testJDBC() throws Exception {
Properties properties = new Properties();
properties.put(“url”, “jdbc:elasticsearch://127.0.0.1:9300/test” );
DruidDataSource dds = (DruidDataSource) ElasticSearchDruidDataSourceFactory.createDataSource(properties);
Connection connection = dds.getConnection();
PreparedStatement ps = connection.prepareStatement(“SELECT province,count(*)as count from crawler/log where method=’getPhone’and status=4 and sellId=’chinaunicom’and methondType=’response’ and timeStamp.keyword between ‘2017-06-08 00:00:00’ and ‘2017-06-08 24:00:00’ group by province “);
ResultSet resultSet = ps.executeQuery();
while (resultSet.next()) {
//result.add(resultSet.getString("sillId") + "," + resultSet.getInt("province") + "," + resultSet.getString("account"));
System.out.println(resultSet.getString("province"));
sucReqNum=(int)(resultSet.getDouble("count"));
System.out.println(sucReqNum);
}
ps.close();
“`