ElasticSearch로 일본어 검색을 위한 로컬 환경 구축

ElasticSearch × 형태소 해석

환경 구축해 보자



여기 에서 최신 버전을 DL, 적절한 디렉토리에 압축을 풉니 다.
Java 설치 및 경로를 통해 둡시다.

일본어로 검색하고 싶으므로 kuromoji plugin을 설치합니다.
내 환경에서는 프록시를 통과해야했습니다.
Windows에서는 다음 명령으로 OK. 공식 문서 그럼 "(더블 쿼트 첨부)의 기술이 있었습니다만 잘 가지 않고,"를 지우면 인스톨 할 수 있었습니다.
# set ES_JAVA_OPTS=-Dhttp.proxyHost=**.**.**.** -Dhttp.proxyPort=**** Dhttps.proxyHost=**.**.**.** -Dhttps.proxyPort=****
# elasticsearch\bin\elasticsearch-plugin install analysis-kuromoji

시작해 보겠습니다.
# elasticsearch\bin\elasticsearch.bat

http://localhost:9200 를 방문하여 다음과 같은 Json을 얻을 수 있으면 완료됩니다.
{
  "name": "aV33ZuH",
  "cluster_name": "elasticsearch",
  "cluster_uuid": "-rHtAb19QzKUiJ1_aq_-ig",
  "version": {
    "number": "5.4.1",
    "build_hash": "2cfe0df",
    "build_date": "2017-05-29T16:05:51.443Z",
    "build_snapshot": false,
    "lucene_version": "6.5.1"
  },
  "tagline": "You Know, for Search"
}

검색해보기



적당히 데이터를 등록해 보겠습니다.
curl -XPOST http://localhost:9200/test/sample -d '{
  "id" : "1",
  "text" : "夏なのでアイスがおいしい季節になりました"
}'
curl -XPOST http://localhost:9200/test/sample -d '{
  "id" : "2",
  "text" : "桃アイスを頂いた"
}'
curl -XPOST http://localhost:9200/test/sample -d '{
  "id" : "2",
  "text" : "昨日桃ちゃんと遊んだよ"
}'

검색해 보겠습니다.
curl -XPOST http://localhost:9200/test/sample/_search -d '{
  "query": {
    "match": {
      "text": "アイスが"
    }
  }
}
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 0.5398108,
    "hits": [
    {
      "_index": "test",
      "_type": "sample",
      "_id": "AVzERcmBSCe8bM-UJRG3",
      "_score": 0.5398108,
      "_source": {
        "id": "1",
        "text": "夏なのでアイスがおいしい季節になりました"
      }
    },
    {
      "_index": "test",
      "_type": "sample",
      "_id": "AVzERh6cSCe8bM-UJRG4",
      "_score": 0.2824934,
      "_source": {
        "id": "2",
        "name": "桃アイスを頂いた"
      }
    }
    ]
  }
}

검색 단어의 '아이스가'의 조사가 생략되어 있음을 알 수 있습니다.

좋은 웹페이지 즐겨찾기