个人实现 elasticsearch的jdbc驱动,略微参考官方 x-pack-sql-jdbc (7.6.2,其他版本未测试),相当于精简官方jdbc,同时又绕过权限问题
源码https://gitee.com/wsitm/elasticsearch-jdbc.git
引用自行使用源码打包,或
取pack目录下我打包好的jar文件。然后放在在spingboot项目下
选中“elasticsearch-jdbc-1.0.0-SNAPSHOT.jar”,右键-> Add as Library。
其实比较建议自己构建一个私有仓库再引用,相对方便。这个是个人兴趣,所有我就不发布到maven仓库了,太麻烦
另外,该工具使用fastjson作核心数据处理,必须在 pom 引用
com.alibaba
fastjson
1.2.78
配置
- yml配置文件
spring:
datasource:
driver-class-name: stu.elasticsearch.jdbc.EsDriver
url: jdbc:es://192.168.0.1:9200/
username: xxx
password: xxxxxx
hikari:
read-only: true #该配置为必须配置
minimum-idle: 3
max-lifetime: 1800000
connection-test-query: select 1
mybatis:
mapper-locations: classpath*:mapper/*Mapper.xml
- mapper接口
@Mapper
public interface EsMapper {
List
- mapper 写SQL的xml文件,其中表名必须使用双引号包含
没有任何多余的配置,就和查其他数据库一样
测试- 测试代码
@SpringBootTest(classes = EsApplication.class)
class EsApplicationTests {
@Autowired
private EsMapper esMapper;
@Test
void test() {
List
- 测试结果



