Install ElasticSearch 9.x on Windows

By | 2025년 10월 26일
Table of Contents

Install ElasticSearch 9.x on Windows

엘라스틱서치가 어떻게 변경되었는지 궁금해서 간단히 윈도우 버전의 ELK 스택을 설치해 봅니다.

ElasticSearch 7.12 이후 버전부터는 JDK 가 내장되어 있습니다.

ElasticSearch 설치 및 실행

  • ELK 폴더 생성
D:\>mkdir ELK
D:\>cd ELK\
cluster.name: test-es
node.name: test-es-node01

path:
  data: ./data
  logs: ./logs

network.host: 127.0.0.1

discovery.type: "single-node"
xpack.security.enabled: false
  • ELK/elasticsearch/config/jvm.options 수정
## 주석 해제
-Xms4g
-Xmx4g
  • 다음 명령어 실행
D:\ELK>elasticsearch\bin\elasticsearch.bat
  • 서비스 등록 후 실행

    실행중인 elasticsearch 를 Ctrl-c 를 눌려서 종료시킨다.

D:\ELK>elasticsearch\bin\elasticsearch-service.bat install
D:\ELK>elasticsearch\bin\elasticsearch-service.bat start
# D:\ELK>elasticsearch\bin\elasticsearch-service.bat stop
D:\ELK>elasticsearch\bin\elasticsearch-service.bat stop

Kibana 설치 및 실행

  • kibana 다운로드 후 압축 해제

    파일 갯수가 많아서 느림 (11만개 이상)

    https://www.elastic.co/kr/downloads/kibana

  • kibana 폴더를 ELK 폴더 밑으로 이동

  • ELK/kibana/config/kibana.yml 수정

server.port: 5601
server.host: localhost
server.publicBaseUrl: "http://localhost:5601"
elasticsearch.hosts: ["http://localhost:9200"]
  • 다음 명령어 실행

    윈도우가 바이러스 검사를 하기 때문에 실행에 시간이 걸립니다. (5~10분)

D:\ELK>kibana\bin\kibana.bat
  • 접속하기

    elasticsearch 는 실행중이어야 합니다.

    http://localhost:5601

  • 테스트하기

    try sample data 버튼을 눌러 샘플 데이타를 볼 수 있습니다.

Korean Jaso Analyzer 를 이용한 자동완성

여기 에서 Korean Jaso Analyzer 를 다운받아 컴파일 및 설치를 합니다.

인덱스 생성

auto_complete.json

{
  "settings": {
    "index": {
      "number_of_replicas": "0",
      "max_ngram_diff": 50,
      "analysis": {
        "filter": {
          "suggest_filter": {
            "type": "ngram",
            "min_gram": 1,
            "max_gram": 50
          }
        },
        "analyzer": {
          "my_ngram_analyzer": {
            "tokenizer": "my_ngram_tokenizer"
          },
          "suggest_search_analyzer": {
            "type": "custom",
            "tokenizer": "jaso_search_tokenizer"
          },
          "suggest_index_analyzer": {
            "type": "custom",
            "tokenizer": "jaso_index_tokenizer",
            "filter": ["suggest_filter"]
          }
        },
        "tokenizer": {
          "jaso_search_tokenizer": {
            "type": "jaso_tokenizer",
            "mistype": true,
            "chosung": false
          },
          "jaso_index_tokenizer": {
            "type": "jaso_tokenizer",
            "mistype": true,
            "chosung": true
          },
          "my_ngram_tokenizer": {
            "type": "ngram",
            "min_gram": "1",
            "max_gram": "10"
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "search_string": {
        "type": "text",
        "fields": {
          "ngram": {
            "type": "text",
            "analyzer": "my_ngram_analyzer"
          },
          "jaso": {
            "type": "text",
            "analyzer": "suggest_index_analyzer"
          }
        }
      }
    }
  }
}
# curl -XDELETE "http://localhost:9200/auto_complete?pretty" -H "Content-Type: application/json"
curl -XPUT "http://localhost:9200/auto_complete?pretty" -H "Content-Type: application/json" -d @auto_complete.json

테스트 데이타 생성

중요: 파일 마지막에 반드시 빈 줄(개행)이 하나 있어야 합니다!

bulk_data.json

{ "index":{ "_index" : "auto_complete" } }
{ "search_string":"셀프빨래방"}
{ "index":{ "_index" : "auto_complete" } }
{ "search_string":"빨래건조대"}
{ "index":{ "_index" : "auto_complete" } }
{ "search_string":"볼빨간사춘기"}
{ "index":{ "_index" : "auto_complete" } }
{ "search_string":"빨래건조기"}
curl -XPOST "http://localhost:9200/_bulk?pretty" -H "Content-Type: application/json" --data-binary @bulk_data.json

테스트

search.json

{
  "query": {
    "match": {
      "search_string.ngram": {
        "query": "빨",
        "analyzer": "my_ngram_analyzer"
      }
    }
  },
  "highlight": {
    "fields": {
      "search_string.ngram": {}
    }
  }
}
curl -XGET "http://localhost:9200/auto_complete/_search?pretty" -H "Content-Type: application/json" -d @search.json

답글 남기기