# 실행되고 있는 컨테이너 확인 $ docker ps # compose.yml 파일이 있는 경로에서 아래 명령어 입력 $ docker compose down # 잘 종료됐나 확인 $ docker ps
FROM docker.elastic.co/elasticsearch/elasticsearch:8.17.4 # Nori Analyzer 플러그인 설치 RUN bin/elasticsearch-plugin install analysis-nori
services: elastic: image: docker.elastic.co/elasticsearch/elasticsearch:8.17.4 # 8.17.4 버전 build: context: . dockerfile: Dockerfile ports: - 9200:9200 # 9200번 포트에서 Elasticsearch 실행 environment: # 아래 설정은 개발/테스트 환경에서 간단하게 테스트하기 위한 옵션 (운영 환경에서는 설정하면 안 됨) - discovery.type=single-node # 단일 노드 (지금은 알 필요 없음) - xpack.security.enabled=false # 보안 설정 - xpack.security.http.ssl.enabled=false # 보안 설정 kibana: image: docker.elastic.co/kibana/kibana:8.17.4 # 8.17.4 버전 ports: - 5601:5601 # 5601번 포트에서 kibana 실행 environment: - ELASTICSEARCH_HOSTS=http://elastic:9200 # kibana에게 통신할 Elasticsearch 주소 알려주기
$ docker compose up -d # 잘 실행됐나 확인 $ docker ps
// 방법 1 GET /_analyze { "text": "백화점에서 쇼핑을 하다가 친구를 만났다.", "analyzer": "nori" } // 방법 2 (nori analyzer의 구성을 직접 명시) GET /_analyze { "text": "백화점에서 쇼핑을 하다가 친구를 만났다.", "char_filter": [], "tokenizer": "nori_tokenizer", "filter": ["nori_part_of_speech", "nori_readingform", "lowercase"] }
nori_part_of_speech : 의미 없는 조사(을, 의 등), 접속사 등을 제거nori_readingform : 한자를 한글로 바꿔서 토큰으로 저장{ "tokens": [ { "token": "백화", "start_offset": 0, "end_offset": 2, "type": "word", "position": 0 }, { "token": "점", "start_offset": 2, "end_offset": 3, "type": "word", "position": 1 }, { "token": "쇼핑", "start_offset": 6, "end_offset": 8, "type": "word", "position": 3 }, { "token": "하", "start_offset": 10, "end_offset": 11, "type": "word", "position": 5 }, { "token": "친구", "start_offset": 14, "end_offset": 16, "type": "word", "position": 7 }, { "token": "만나", "start_offset": 18, "end_offset": 20, "type": "word", "position": 9 } ] }
// 기존 인덱스 삭제 DELETE /boards // 인덱스 생성 + 매핑 정의 + Custom Analyzer 적용 PUT /boards { "settings": { "analysis": { "analyzer": { "boards_content_analyzer": { "char_filter": [], "tokenizer": "nori_tokenizer", "filter": ["nori_part_of_speech", "nori_readingform", "lowercase"] } } } }, "mappings": { "properties": { "content": { "type": "text", "analyzer": "boards_content_analyzer" } } } } // 잘 생성됐는 지 확인 GET /boards
POST /boards/_doc { "content": "백화점에서 쇼핑을 하다가 친구를 만났다." }
GET /boards/_search { "query": { "match": { "content": "백화점" } } } GET /boards/_search { "query": { "match": { "content": "쇼핑" } } } GET /boards/_search { "query": { "match": { "content": "친구" } } }