项目用处
Doris通过创建外部表方式将Doris的分布式查询规划能力和ES(Elasticsearch)的全文检索能力相结合,提供更完善的 OLAP 分析场景解决方案,支持:
- ES 中的多index分布式Join查询
- Doris 和 ES 中的表联合查询,更复杂的全文检索过滤
配置过程
实验环境: doris 版本2.0.9, Elasticsearch 版本8.7.1,在 wsl2-ubuntu22.0.4 上部署
doris 的配置可以参考官方文档, Elasticsearch 的配置可以参考这篇文章 只需要看 Elasticsearch 配置部分就ok了
对于 Elasticsearch 的配置,作者有个小技巧,就是现在本机配置好后,再把整个文件夹复制到虚拟机的 /home/user 目录下,如果有报错文件无法复制过去的直接跳过就好,不影响使用
虚拟机的目录可以通过在资源管理器地址栏中输入 \wsl.localhost\ 找到,我的是 \wsl.localhost\Ubuntu
配置 Elasticsearch 过程中作者遇到了没有 tools.jar 报错,需要自行下载 tools.jar,并放入安装目录 \jdk-x.x.x\lib 中
单节点查询
创建doris外部表
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| CREATE EXTERNAL TABLE `es_table` ( `id` long COMMENT "", `k1` bigint(20) COMMENT "", `k2` datetime COMMENT "", `k3` varchar(20) COMMENT "", `k4` varchar(100) COMMENT "", `k5` float COMMENT "" ) ENGINE=ELASTICSEARCH PARTITION BY RANGE(`id`) PROPERTIES ( "connector" = "elasticsearch", "host" = "http://es_ip:es_port(一般是9200)", "index" = "test" );
|
ES 创建 test 索引
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| curl -X PUT "http://es_ip:es_port/test" -H 'Content-Type: application/json' -d ' { "mappings": { "properties": { "id": { "type": "long" }, "k1": { "type": "long", "index": true }, "k3": { "type": "text" }, "k4": { "type": "text" }, "k5": { "type": "float" }, "k2": { "type": "date", "format": "yyyy-MM-dd" } } } }'
|
ES 添加数据
1 2 3 4 5 6 7 8
| curl -X POST "http://es_ip:es_port/test/_doc" -H 'Content-Type: application/json' -d '{ "id": 1001, "k1": 100, "k2": "2020-01-01", "k3": "Trying", "k4": "Trying out Elasticsearch", "k5": 10 }'
|
数据添加成功后,在mysql客户端连接doris查询ES数据
ES 批量添加数据
1 2 3 4 5 6 7 8 9 10 11 12
| curl -X POST "http://es_ip:es_port/_bulk" -H 'Content-Type: application/json' -d ' {"index":{"_index":"test"}} { "id": "1", "k1" : 100, "k2": "2020-01-01", "k3": "Trying out Elasticsearch", "k4": "Trying out Elasticsearch", "k5": 10.0} {"index":{"_index":"test"}} { "id": "2", "k1" : 100, "k2": "2020-01-01", "k3": "Trying out Doris", "k4": "Trying out Doris", "k5": 10.0} {"index":{"_index":"test"}} { "id": "3", "k1" : 100, "k2": "2020-01-01", "k3": "Doris On ES", "k4": "Doris On ES", "k5": 10.0} {"index":{"_index":"test"}} { "id": "4", "k1" : 100, "k2": "2020-01-01", "k3": "Doris", "k4": "Doris", "k5": 10.0} {"index":{"_index":"test"}} { "id": "5", "k1" : 100, "k2": "2020-01-01", "k3": "ES", "k4": "ES", "k5": 10.0} '
|
数据添加成功后,在mysql客户端连接doris查询ES数据
在doris中执行模糊匹配查询
1 2 3 4 5 6
| select * from es_table where esquery(k4, '{ "match": { "k4": "elasticsearch" } }'); # 要自己处理一下换行
|
预期应用
doris 和 ES 都是作者实训课程中所开发项目的其中一部分,但是作者并未学会如何应用到项目中,本文只是一次调研