포스트

Zombodb - pg10 plugin for ES6

Postgresql 과 Elasticsearch 를 연동시키는 Zombodb 라는 플러그인을 설치하는 방법을 설명합니다.

Zombodb - pg10 plugin for ES6

Zombodb 설치

출처 : Github zombodb

  • Zombodb configuration
  • zombodb–10-1.0.3.sql

CentOS 6 환경 (installed by yum)

PATH /usr/pgsql-10/share/extension/zombodb--10-1.0.3.sql

Mac OS 환경 (installed by brew)

PATH /usr/local/Cellar/postgresql@10/10.6_1/share/postgresql@10/extension/zombodb--10-1.0.3.sql

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
INSERT INTO analyzers(name, definition, is_default) VALUES (
  'zdb_korean', '{
          "type": "custom",
          "tokenizer": "nori_tokenizer",
          "filter": [
            "lowercase",
            "nori_part_of_speech"
          ]
        }', true);

CREATE DOMAIN text_ko AS text;

-- INSERT INTO type_mappings(type_name, definition, is_default) VALUES (
--   'text', '{
--     "type": "text",
--     "copy_to": "zdb_all",
--     "fielddata": true,
--     "analyzer": "zdb_standard"
--   }', true);

INSERT INTO type_mappings(type_name, definition, is_default) VALUES (
  'text_ko', '{
    "type": "text",
    "copy_to": "zdb_all",
    "analyzer": "zdb_korean"
  }', true);

CREATE DOMAIN korean AS text;      -- nori_analyzer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "analyzer [korean] not found for field [sentence]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [doc]: analyzer [korean] not found for field [sentence]",
    "caused_by": {
      "type": "mapper_parsing_exception",
      "reason": "analyzer [korean] not found for field [sentence]"
    }
  },
  "status": 400
}

ZomboDB 인덱스 생성 및 테스트

ElasticSearch 서버 http://localhost:9200 에 인덱스 연결

1
2
3
create index idx_products on idx_products
  using zombodb((products.*))
  with (url='http://localhost:9200');

create-zombodb-index ZomboDB 인덱스 생성 명령

ElasticSearch 의 쿼리 결과를 인덱스로 사용해 Postgresql 의 테이블을 쿼리한다.

1
2
3
4
5
6
7
-- 텍스트 통합 필드에 대해 키워드를 쿼리
select * from products
where products ==> 'mix';

-- 특정 필드에 대해 값을 쿼리
select * from products
where products ==> 'productname:"chai"';

create-zombodb-index-query ZomboDB 인덱스 생성된 결과

 
 

끝!   읽어주셔서 감사합니다.

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.