postgres elasticsearch fdw 学习

es 的fdw 是基于multicorn(python扩展)开发的,官方的multicorn 版本已经很老了,对于pg 的高版本是不支持的
但是已经有人提供了支持新版本的包了,还是很不错的,基于python 开发fdw 简单方便

multicorn 支持的版本

apt-get install postgresql-9.4-python-multicorn
apt-get install postgresql-9.5-python-multicorn
apt-get install postgresql-9.6-python-multicorn
apt-get install postgresql-10-python-multicorn
apt-get install postgresql-11-python-multicor

es fdw docker 镜像

  • Dockerfile

    9.5 版本的,es 为7 (默认使用es python 的最新版本)

FROM postgres:9.5
RUN apt-get update && apt-get -y install \
        postgresql-9.5-python-multicorn \
        python-pip \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*
RUN pip install pg_es_fdw

环境准备

  • docker-compose 文件
version: "3"
services:
  elasticsearch:
    image: elasticsearch:7.6.0
    environment:
      - "discovery.type=single-node"
      - "http.host=0.0.0.0"
      - "cluster.name=odfe-cluster"
      - "transport.host=0.0.0.0"
      - "network.host=0.0.0.0"
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ports:
    - 9200:9200
  psotgres-fdw:
    image: dalongrong/pg-es-fdw:9.5
    ports:
      - "5432:5432"
    environment:
      - "POSTGRES_PASSWORD=dalong"

启动&&使用

  • 启动
docker-compose up -d
  • 使用
// 创建扩展
CREATE EXTENSION multicorn;
//  创建 
CREATE SERVER multicorn_es FOREIGN DATA WRAPPER multicorn
OPTIONS (
  wrapper 'pg_es_fdw.ElasticsearchFDW'
);
//  创建外部表映射
CREATE FOREIGN TABLE articles_es
    (
        id BIGINT,
        title TEXT,
        body TEXT,
        query TEXT,
        score NUMERIC
    )
SERVER multicorn_es
OPTIONS
    (
        host 'elasticsearch',
        port '9200',
        index 'article-index',
        type 'article',
        rowid_column 'id',
        query_column 'query',
        score_column 'score',
        timeout '20'
    )
;
// insert 数据
INSERT INTO articles_es
    (
        id,
        title,
        body
    )
VALUES
    (
        1,
        'foo',
        'spike'
    );
  • 效果

 

 


 

 

说明

dockerhub 中我已经push 了9.5 以及11的版本,可以体验试用,为dalongrong/pg-es-fdw:9.5 , dalongrong/pg-es-fdw:11

参考资料

https://github.com/matthewfranglen/postgres-elasticsearch-fdw
https://hub.docker.com/repository/docker/dalongrong/pg-es-fdw
https://github.com/rongfengliang/es-fdw-learning

posted on   荣锋亮  阅读(1492)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-02-24 Optimizing Docker Images for Rust Projects
2019-02-24 bloom-server 基于 rust 编写的 rest api cache 中间件
2016-02-24 Collection+JSON 文档

导航

< 2025年3月 >
23 24 25 26 27 28 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 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示