본문 바로가기
Q&A2022년 9월 10일1분 읽기

Elasticsearch 기본 사용법

허
허진우
조회 398댓글 1

Elasticsearch로 검색 기능을 구현하고 싶은데 기본 사용법을 알려주세요.

댓글 1

김김영삼4년 전

Elasticsearch 기본:

# Docker로 설치
docker run -d -p 9200:9200 -e "discovery.type=single-node" elasticsearch:8.5.0

# 인덱스 생성
curl -X PUT "localhost:9200/posts" -H "Content-Type: application/json" -d '{
"mappings": {
"properties": {
"title": { "type": "text", "analyzer": "standard" },
"content": { "type": "text" },
"created_at": { "type": "date" }
}
}
}'

# 문서 추가
curl -X POST "localhost:9200/posts/_doc" -H "Content-Type: application/json" -d '{
"title": "Elasticsearch 시작하기",
"content": "검색 엔진 기본 사용법",
"created_at": "2022-09-15"
}'

# 검색
curl "localhost:9200/posts/_search?q=검색"

한국어 검색을 위해서는 nori 플러그인(한국어 형태소 분석기)을 설치하세요.

Ctrl+Enter로 등록