15
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mac で Elasticsearch 6

Last updated at Posted at 2017-12-13

事情があってelasticsearchの導入をしようとしているのですが、何も考えずに導入したv6は出たばかりのバージョンらしく、解説がどこにもない。。。

苦労して導入中のメモを残しておきます。

java8の導入

(JDKがないと言われたので、javaを導入したらjava9でダメ)

$ brew cask install java8

elasticsearch 導入 & 自動起動の設定

$ brew install elasticsearch
$ ln -sfv /usr/local/opt/elasticsearch/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist

URL: http://localhost:9200

うまくいくと、下のような結果がブラウザに返ってきます。

{
  "name" : "5egFqAz",
  "cluster_name" : "elasticsearch_makaishi",
  "cluster_uuid" : "Yw_85VZrRwigNvlIl0rD4g",
  "version" : {
    "number" : "6.0.1",
    "build_hash" : "601be4a",
    "build_date" : "2017-12-04T09:29:09.525Z",
    "build_snapshot" : false,
    "lucene_version" : "7.0.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

プラグインの導入

$ cd /usr/local/Cellar/elasticsearch/6.0.1
$ bin/elasticsearch-plugin install analysis-icu
$ bin/elasticsearch-plugin install analysis-kuromoji

index作成

$ curl -X PUT http://localhost:9200/test

index設定確認

$ curl -X GET localhost:9200/test/_stats?pretty=true

データ投入

content-typeを指定する必要あり

$ curl -H "Content-Type: application/json" -XPOST localhost:9200/index/type -d '{"message": "test message"}'

kibanaの導入・起動

$ brew install kibana
$ kibana

url: http://localhost:5601/

うまくいくとこういう画面が出てきます。

スクリーンショット 2018-01-27 20.47.05.png

kuromojiの設定について

kibanaの管理コンソールより行います。
左のメニューからDev Toolsを選び、以下のPUT文をコピペして実行ボタン

PUT test_jp_map 
{
    "settings": {
        "analysis": {
            "filter": {
                "synonyms_filter": {
                    "type": "synonym",
                    "synonyms": [
                        "タブホ,たぶ ほ"
                    ]
                }
            },
            "analyzer": {
                "jpn-search": {
                    "type": "custom",
                    "char_filter": [
                        "icu_normalizer",
                        "kuromoji_iteration_mark"
                    ],
                    "tokenizer": "kuromoji_tokenizer",
                    "filter": [
                        "synonyms_filter",
                        "kuromoji_baseform",
                        "kuromoji_part_of_speech",
                        "ja_stop",
                        "kuromoji_number",
                        "kuromoji_stemmer"
                    ]
                },
                "jpn-index": {
                    "type": "custom",
                    "char_filter": [
                        "icu_normalizer",
                        "kuromoji_iteration_mark"
                    ],
                    "tokenizer": "kuromoji_tokenizer",
                    "filter": [
                        "kuromoji_baseform",
                        "kuromoji_part_of_speech",
                        "ja_stop",
                        "kuromoji_number",
                        "kuromoji_stemmer"
                    ]
                }
            }
        }
    }
}

スクリーンショット 2018-01-27 21.23.53.png

個々の設定の意味についてはElasticsearchを日本語で使う設定のまとめに詳しいです。

形態素エンジンのテスト

下記のPOST文をDev Toolsにコピペして「実行」ボタン

POST test_jp_map/_analyze
{
  "analyzer": "jpn-search",
  "text": "すもももももももものうち"
}

結果

スクリーンショット 2018-01-27 21.35.21.png

関連リンク solrで日本語形態素解析結果を調べる(Mac版)

15
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?