概述
ZomboDB使用Elasticsearch作為索引類型,為Postgres帶來強大的文本搜索和分析功能。它全面的查詢語言和SQL函數(shù)支持新的和創(chuàng)造性的方式來查詢您的關(guān)系數(shù)據(jù)。
從技術(shù)角度來看,ZomboDB是一個100%本地Postgres擴展,實現(xiàn)Postgres的索引訪問方法API。作為本地Postgres索引類型,ZomboDB允許在現(xiàn)有的g表上使用ZOBODB創(chuàng)建索引
CREATE INDEX ... USING zombodb。這時,ZomboDB接管并完全管理遠(yuǎn)程Elasticsearch索引,并保證文本搜索結(jié)果的事務(wù)性正確。
ZomboDB允許您直接從Postgres使用Elasticsearch的強大功能和可伸縮性。您不必管理pg和es之間的事務(wù)同步和彈性搜索、異步索引管道、復(fù)雜的重新索引過程或多個數(shù)據(jù)訪問代碼路徑之間的事務(wù)——ZOBODB打包完成。
安裝需求
- Postgres 10.x, 11.x
- Elasticsearch 5.6.x, 6.x
- libcurl >=7.28.0 -多協(xié)議文件傳輸庫
安裝Postgres
https://www.cnblogs.com/zhi-leaf/p/11432054.html 這個下面基本上走一遍沒有問題
CentOS版本:CentOS-7-x86_64-Minimal-1810
PostgreSQL版本: PostgreSQL 10.10, 64-bit
安裝zombodb擴展
- 下載pg10 版本的擴展
wget https://www.zombodb.com/releases/v10-1.0.3/zombodb_centos7_pg10-10-1.0.3_1.x86_64.rpm - 安裝zombodb
rpm -Uvh zombodb_centos7_pg10-10-1.0.3_1.x86_64.rpm
之前采坑主要是沒有用centos的系統(tǒng),用的ubuntu就全是坑,改成centos一遍就好了
安裝ES
Elasticsearch版本: 6.6.0
https://www.cnblogs.com/rongfengliang/p/10635311.html 這個鏈接下面會裝pg會有很多問題,裝es是沒問題的
- 安裝docker
yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce
- docker 加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://b3uey254.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
- 創(chuàng)建docker-compose.yml
version: '2'
services:
elasticsearch:
image: elasticsearch:6.6.0
ports:
- "9200:9200"
environment:
- http.host=0.0.0.0
- transport.host=0.0.0.0
- network.host=0.0.0.0
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
mem_limit: 1g
- 配置系統(tǒng)vm 參數(shù)
echo vm.max_map_count=655360 >> /etc/sysctl.conf && sysctl -p - 在文件目錄啟動
docker-compose up -d
測試案例
- 創(chuàng)建擴展
CREATE EXTENSION zombodb; - 創(chuàng)建測試表
id SERIAL8 NOT NULL PRIMARY KEY,
name text NOT NULL,
keywords varchar(64)[],
short_summary text,
long_description zdb.fulltext,
price bigint,
inventory_count integer,
discontinued boolean default false,
availability_date date
);
- 導(dǎo)入測試數(shù)據(jù)
COPY products FROM PROGRAM 'curl https://raw.githubusercontent.com/zombodb/zombodb/master/TUTORIAL-data.dmp'; - 創(chuàng)建索引
CREATE INDEX idxproducts
ON products
USING zombodb ((products.*))
WITH (url='http://localhost:9200/');
-
datagrip連接pg查看表結(jié)構(gòu)
數(shù)據(jù)表結(jié)構(gòu)及zombodb插件
- 查詢
SELECT * FROM products WHERE products ==> 'sports box';
查詢數(shù)據(jù)
引用
https://github.com/zombodb/zombodb#making-postgres-and-elasticsearch-work-together-like-its-2019
https://www.cnblogs.com/zhi-leaf/p/11432054.html
https://www.cnblogs.com/rongfengliang/p/10635311.html

