CentOS 6.4 に yum でインストール
$ sudo rpm --import http://packages.elasticsearch.org/GPG-KEY-elasticsearch
$ sudo vim /etc/yum.repos.d/elasticsearch.repo
elasticsearch.repo
[elasticsearch-1.3]
name=Elasticsearch repository for 1.3.x packages
baseurl=http://packages.elasticsearch.org/elasticsearch/1.3/centos
gpgcheck=1
gpgkey=http://packages.elasticsearch.org/GPG-KEY-elasticsearch
enabled=1
$ sudo yum install elasticsearch
起動
$ sudo service elasticsearch start
起動したか確認
$ curl -XGET http://localhost:9200/
結果
{
"status" : 200,
"name" : "King Bedlam",
"version" : {
"number" : "1.3.1",
"build_hash" : "2de6dc5268c32fb49b205233c138d93aaf772015",
"build_timestamp" : "2014-07-28T14:45:15Z",
"build_snapshot" : false,
"lucene_version" : "4.9"
},
"tagline" : "You Know, for Search"
}
実践!Elasticsearch - Wantedly Engineer Blog を実行してみる
プラグインのインストール
$ sudo /usr/share/elasticsearch/bin/plugin -install elasticsearch/marvel/latest
$ sudo /usr/share/elasticsearch/bin/plugin -install polyfractal/elasticsearch-inquisitor
$ sudo /usr/share/elasticsearch/bin/plugin -install elasticsearch/elasticsearch-analysis-kuromoji/2.1.0
アナライザの登録
$ curl -XPUT 'http://localhost:9200/wantedly-demo' -d \
'{
"settings": {
"analysis": {
"filter": {
"pos_filter": {
"type": "kuromoji_part_of_speech",
"stoptags": [
"助詞-格助詞-一般",
"助詞-終助詞"
]
},
...(省略)...
}'
データのインポート
$ sudo curl -XPOST 'http://localhost:9200/_bulk' -d \
'
{ "index": { "_index": "wantedly-demo", "_type": "company", "_id": "1" } }
{ "id": "1", "name": "wantedly", "location": "東京都港区白金台 3-19-6 白金台ビル3F" }
'
結果
{
"took": 4,
"errors": true,
"items": [
{
"index": {
"_index": "wantedly-demo",
"_type": "company",
"_id": "1",
"status": 500,
"error": "NoClassDefFoundError[org/apache/lucene/util/AttributeSource$AttributeFactory]"
}
}
]
}
だめぽ(><)
ちなみに status が yellow なんですけど、何が悪いんでしょうか?
$ curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
結果
{
"cluster_name" : "elasticsearch",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 13,
"active_shards" : 13,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 13
}
追記:
Elasticsearch の中の人、@johtani さんにコメントを頂きました。
kuromoji のバージョンが es のバージョンと合ってなかったらしい(es 1.3 系ならこのブランチ)
↓Wantedly のサイトにもこう書いてある!ケアレスミス!
インストールした elasticsearch のバージョンに合わせて適切なプラグインのバージョンを使ってください。
コメント通り、いったん削除してから入れなおす。
$ sudo /usr/share/elasticsearch/bin/plugin --remove elasticsearch/elasticsearch-analysis-kuromoji
$ sudo /usr/share/elasticsearch/bin/plugin -install elasticsearch/elasticsearch-analysis-kuromoji/2.3.0
elasticsearch をリスタート。
$ service elasticsearch restart
データのインポート
$ sudo curl -XPOST 'http://localhost:9200/_bulk' -d \
'
{ "index": { "_index": "wantedly-demo", "_type": "company", "_id": "1" } }
{ "id": "1", "name": "wantedly", "location": "東京都港区白金台 3-19-6 白金台ビル3F" }
'
結果
{
"took": 224,
"errors": false,
"items": [
{
"index": {
"_index": "wantedly-demo",
"_type": "company",
"_id": "1",
"_version": 1,
"status": 201
}
}
]
}
うまくいった・・・のか?
試しに下記のクエリを投げてみる。
GET /wantedly-demo/_search
{
"query": {
"simple_query_string": {
"query": "白金台"
}
}
}
結果
{
"took": 14,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.011502187,
"hits": [
{
"_index": "wantedly-demo",
"_type": "company",
"_id": "1",
"_score": 0.011502187,
"_source": {
"id": "1",
"name": "wantedly",
"location": "東京都港区白金台 3-19-6 白金台ビル3F"
}
}
]
}
}
できたぽい!!!
ありがとう @johtani さん!