【进行中】安装 Elasticsearch
正如这里所写的那样,Elasticsearch参考[1.5]» 配置» 仓库
建立环境
$ cat /etc/redhat-release ; uname -a
CentOS release 6.6 (Final)
Linux moon 2.6.32-504.16.2.el6.x86_64 #1 SMP Wed Apr 22 06:48:29 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
安装Java
- OracleのJDKをインストールする
Java SE 开发工具包7的下载
从上述地址下载最新版本
截至2015/06/04,[Java SE 开发工具包7u79]是最新版本
# sudo rpm -ihv jdk-7u79-linux-x64.rpm
$ java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
CentOS系统(通过yum)
- レポジトリの取得(ver 1.5)
[elasticsearch-1.5]
name=Elasticsearch repository for 1.5.x packages
baseurl=http://packages.elastic.co/elasticsearch/1.5/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
- インストール
$ sudo yum install elasticsearch
- 起動
$ sudo service elasticsearch start
- 起動確認
curl -X GET http://localhost:9200/
$ curl -X GET http://localhost:9200/
{
"status" : 200,
"name" : "Right-Winger",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "1.5.2",
"build_hash" : "62ff9868b4c8a0c45860bebb259e21980778ab1c",
"build_timestamp" : "2015-04-27T09:21:06Z",
"build_snapshot" : false,
"lucene_version" : "4.10.4"
},
"tagline" : "You Know, for Search"
}
- 上記正常に起動出来る事が分かったのでサーバ起動時に自動起動設定
$ sudo chkconfig elasticsearch on
$ sudo chkconfig elasticsearch --list
确认动作
- データを登録
# curl -XPUT http://localhost:9200/mytest/test/1 -d '{ "title":"memo", "text":"ほげほげ" }'
{"_index":"mytest","_type":"test","_id":"1","_version":1,"created":true}
- データの確認
$ curl -XGET http://localhost:9200/mytest/test/_search -d '{ "query": { "match": { "title":"memo" } } }'
{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}
- データの削除
$ curl -XDELETE http://localhost:9200/mytest/test/1
{"found":false,"_index":"mytest","_type":"test","_id":"1","_version":1}
安装适用于Elasticsearch的日语支持插件(kuromoji)。
- elastic/elasticsearch-analysis-kuromoji
截至2015年6月4日,es1.5x系列已支持elasticsearch-analysis-kuromoji/2.5.0。
$ sudo bin/plugin install elasticsearch/elasticsearch-analysis-kuromoji/2.5.0
- 設定の反映のために、esの再起動
$ sudo service elasticsearch restart
通过kuromoji-analyzer进行动作确认。
- データの投入
$ curl -XPUT http://localhost:9200/kuromoji_sample -d '{ "index": { "analysis": { "tokenizer": { "kuromoji_user_dict" : { "type":"kuromoji_tokenizer" } }, "analyzer": { "analyzer": { "type":"custom", "tokenizer": "kuromoji_user_dict" } } } } }'
{"acknowledged":true}
- この新しく作成したインデックスに対して日本語文字列を POST して、形態素解析が有効になっているかどうかを確認
$ curl -XPOST 'http://localhost:9200/kuromoji_sample/_analyze?analyzer=analyzer&pretty' -d '月島もんじゃ'
{
"tokens" : [ {
"token" : "月島",
"start_offset" : 0,
"end_offset" : 2,
"type" : "word",
"position" : 1
}, {
"token" : "もんじゃ",
"start_offset" : 2,
"end_offset" : 6,
"type" : "word",
"position" : 2
} ]
}
- kuromoji を使ったインデックスを ElasticSearch のデフォルトアナライザとして指定し、ElasticSearch を再起動します
$ sudo echo "index.analysis.analyzer.default.type: custom" >> /etc/elasticsearch/elasticsearch.yml
$ sudo echo "index.analysis.analyzer.default.tokenizer: kuromoji_user_dict" >> /etc/elasticsearch/elasticsearch.yml
$ sudo service elasticsearch restart
- 改めて、データの投入
$ curl -XPUT http://localhost:9200/kuromoji_sample/test/1 -d '{ "title":"メモ 1", "text":"今夜の夕食が楽しみ" }'
$ curl -XPUT http://localhost:9200/kuromoji_sample/test/1 -d '{ "title":"メモ 1", "text":"来週の刃牙が楽しみ" }'
{"_index":"kuromoji_sample","_type":"test","_id":"1","_version":2,"created":false}
- データの検索
$ curl -XGET http://localhost:9200/kuromoji_sample/test/_search -d '{"query":{"match":{"text":"刃牙"}}}'
{"took":12,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.16273327,"hits":[{"_index":"kuromoji_sample","_type":"test","_id":"1","_score":0.16273327,"_source":{ "title":"メモ1", "text":"来週の刃牙が楽しみ" }}]}}
请参考以下网址:
http://dotnsf.blog.jp/archives/1005213909.html
其他
- Elastic Headの導入
couchbaselabs/elasticsearch-transport-couchbase可以被改写为:
couchbaselabs/elasticsearch-transport-couchbase库
为了能在浏览器中查看,尝试添加Elastic Head。
$ sudo service elasticsearch stop
$ sudo bin/plugin -install mobz/elasticsearch-head
$ sudo service elasticsearch start
安装完成后,请通过浏览器访问上述内容。
http://(サーバーのIPアドレス):9200/_plugin/head/
