NoSQL의 일종으로 분류가 가능하고 분산 처리를 통해 실시간에 준하는(Near Realtime) 빠른 검색이 가능한 검색엔진(Search Engine)이며 MongoDB나 Hbase처럼 대용량 Storage 처럼 사용 할 수 있다. 기존 관계형 데이터베이스에서 처리하기 어려운 비정형 데이터도 검색할 수 있으며, 전문 검색(Full Text)과 구조 검색 모두를 지원한다.

검색 시스템의 구성요소

일반적으로 검색용 데이터(정보)를 수집하는 수집기, 수집한 데이터를 저장하는 스토리지, 수집한 데이터를 검색에 적절한 형태로 변환하는 색인기(형태소 분석기), 색인된 데이터에서 일치하는 문서를 찾는 검색기로 구성된다.

수집기

수집기는 웹사이트, 블로그, 카페 등 웹에서 필요한 정보를 수집하는 프로그램이다. 크롤러, 스파이더, 웜, 웹 로봇 등으로 불린다.

스토리지

데이터베이스에서 데이터를 저장하는 물리적인 저장소이다. 검색엔진은 색인한 데이터를 스토리지에 보관한다.

색인기

검색엔진이 수집한 데이터에서 사용자 질의와 일치하는 정보를 찾으려면 수집된 데이터를 검색 가능한 구조로 가공하고 저장해야한다. 그 역할을 하는 것이 색인기(형태소 분석기)이다. 색인기는 다양한 형태소 분석기를 조합해 정보에서 의미가 있는 용어를 추출하고 검색에 유리한 역색인 구조(Inverted Index)로 데이터를 저장한다.

검색기

검색기는 사용자 질의를 입력받아 색인기에서 저장한 역색인 구조에서 일치하는 문서를 찾아 결과로 반환한다. 질의와 문서가 일치하는지는 유사도 기반의 검색 순위 알고리즘으로 판단한다. 검색기 또한 색인기와 마찬가지로 형태소 분석기를 이용해 사용자 질의에서 유의미한 용러를 추출해 검색한다.

실제로 ES(Elasticsearch)에서 검색 Query를 작성할 때 형태소 분석기를 설정하는 필드명이 있다. 분석기를 선택해서 검색을 하면 검색어가 형태소 분석기를 통해서 유의미한 용어를 추출하고, 그 추출된 데이터를 이용해서 실질적인 검색을 실행한다.

1. Installation

1.1 Downloaded and install archive

The Linux archive for Elasticsearch 7.x.x can be downloaded and installed as follows :

wget <https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.1-linux-x86_64.tar.gz>
wget <https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.1-linux-x86_64.tar.gz.sha512>
shasum -a 512 -c elasticsearch-7.7.1-linux-x86_64.tar.gz.sha512 
tar -xzf elasticsearch-7.7.1-linux-x86_64.tar.gz
cd elasticsearch-7.7.1/

1.2 Edit config

Elasticsearch가 설치된 Directory 하위에 보면 config/elasticsearch.yml 설정 파일이 있으며, 색인 된 데이터가 저장될 저장 공간의 위치나, Cluster 설정 등 여러가지 설정을 정의 할 수 있다.

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# <https://www.elastic.co/guide/en/elasticsearch/reference/index.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
# 클러스터로 여러 노드를 하나로 묶을 수 있는데, 여기서 클러스터명을 지정할 수 있다.
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# 엘라스틱서치 노드명을 설정한다. 노드명을 지정하지 않으면 엘라스틱서치가 임의의 이름을 자동으로 부여한다.
# 클러스터 구성을 할 경우, Kibana에서 노드별 정보를 조회할 때 노드의 Identity가 뚜렷하게 구별되야
# 유지보수하는데 생산성이 좋다.
node.name: elasticsearch-A
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# 엘라스틱서치의 색인 데이터가 물리적으로 저장되는 디렉토리 설정
# 하나의 디렉토리를 설정을 해도 상관없고, 2개 이상의 디렉토리로 구성할 수도 있다.
path.data: /path/to/data
path.data: /path/to/data, /path/to/data2
#
# Path to log files:
#
path.logs: /path/to/logs
#
# Path to snapshot files :
# 색인 데이터 백업용으로 repo 디렉토리(백업용)를 설정 해놓으면 색인데이터를 백업할 수 있다.
path.repo: /path/to/repo
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
# 특정 IP만 엘라스틱서치에 접근하도록 허용할 수 있다. 선택적으로 IP를 허용해야 할 경우 [1.1.1.1, 2.2.2.2]
# 와 같이 지정하고, 모든 IP를 허용한다면 0.0.0.0을 지정하면 된다.
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
# 엘라스틱서치 Service Port, 기본 값은 9200
http.port: 9200
#
# 엘라스틱서치 클라이언트가 접근할 수 있는 TCP 포트, 기본 값은 9300번
transport.tcp.port: 9300
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# 노드가 여러 개인 경우 유니캐스트로 활성화된 다른 서버를 찾아서 cluster 환경을 구성한다.
# 하나의 서버에서 2개의 노드를 실행시키는 경우도 있기 때문에 서비스포트까지 기입해주는 것이 좋다.
discovery.zen.ping.unicast.hosts: ["host1:9200", "host2:9200"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes: 2
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#
# 노드의 역할(Master, Data, Ingest)을 선택해서 그에 맞는 동작여부를 지정할 수 있다.
node.master : true
node.data : true
#

1.3 Running

Config 설정까지 완료 했으니, 이제 Elasticsearch를 실행시키면 된다. -d 옵션 : daemon 모드 실행, -p 옵션 : 엘라스틱서치 PID를 pid변수에 저장

cd elasticsearch-7.7.1/
./bin/elasticsearch -d -p pid

1.4 Process Kill