Elasticsearch 설치

Minseop Jeong·2022년 4월 7일
0

설치 command

Install and Run Elasticsearch

docker network create elastic
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.1.2
docker run --name es-node01 --net elastic -p 9200:9200 -p 9300:9300 -it docker.elastic.co/elasticsearch/elasticsearch:8.1.2

CMDs for setting

# copy http security crt
docker cp es-node01:/usr/share/elasticsearch/config/certs/http_ca.crt .

# get response from elasticsearch
curl -X GET "https://localhost:9200" -u "elastic:{pw}" --cacert http_ca.crt

# http_ca.crt를 /etc/ssl/cert.pem에 등록하여 사용

Disable xpack security

# attach into docker container
docker exec -it es-node01 /bin/bash

vi /usr/share/elasticsearch/config/elasticsearch.yml

# disable xpack security - modify line as below
xpack.security.enabled: false

Install and Run Kibana

docker pull docker.elastic.co/kibana/kibana:8.1.2
docker run --name kib-01 --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.1.2
  • Elasticsearch docker 이미지를 실행시키면 enrollment token이 생성되는데, localhost:5601 로 접속후, enrollment token과 user info를 입력하고 Kibana에 접속할 수 있다.

Elasticsearch 기본 명령어

index 조회

# index 조회
curl -X GET "http://localhost:9200/_cat/indices?v"

index 추가

index=user, doc_id=1에 {"username": "kin"} document를 추가한다.

curl -X PUT "http://localhost:9200/user/_doc/1" -H "Content-Type: application/json" -d '{"username": "kin"}'

document 조회

curl -X GET "http://localhost:9200/user/_doc/1"

pretty option을 주면 가독성 좋게 볼 수 있다.

curl -X GET "http://localhost:9200/user/_doc/1?pretty"

mapping 조회

curl -X GET "http://localhost:9200/user/_mapping?pretty"

Reference

profile
Data Engineer

0개의 댓글