ライセンス管理 xpack
有効期限の確認方法:
curl -XGET http://localhost:9200/_xpack/license?pretty
ライセンス登録:https://register.elastic.co/
ライセンス更新コマンド:
curl -XPUT -u elastic 'http://localhost:9200/_xpack/license?acknowledge=true' -H "Content-Type: application/json" -d @license.json
ローカルElasticsearch環境
ダウンロードURL:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-10-0
config/elasticsearch.yml設定例:
# クラスター設定
cluster.name: "developmentCluster"
# ノード識別子
node.name: masterNode
# マスターノード資格
node.master: true
# データ保持機能
node.data: true
# 外部アクセス許可
network.host: 0.0.0.0
# HTTPポート番号
http.port: 9200
# 内部通信ポート
transport.tcp.port: 9300
# CORS設定
http.cors.enabled: true
# クロスオリジン許可
http.cors.allow-origin: "*"
メモリ割り当て設定
Docker環境での指定方法:
-e ES_JAVA_OPTS="-Xms2g -Xmx2g"
インストール版のjvm.options変更:
-Xms2g
-Xmx2g
日本語形態素解析プラグイン
取得先:https://github.com/medcl/elasticsearch-analysis-ik
ESバージョン7.10.0に対応したIKアナライザーのインストール:
cd elasticsearch-root/plugins
mkdir japanese-analyzer
cd japanese-analyzer
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.10.0/elasticsearch-analysis-ik-7.10.0.zip
unzip elasticsearch-analysis-ik-7.10.0.zip
プラグイン管理ツールによる自動インストール:
cd elasticsearch-root/bin
./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.10.0/elasticsearch-analysis-ik-7.10.0.zip
動作検証
curl -XPOST http://localhost:9200/test_index/_mapping -H 'Content-Type:application/json' -d'
{
"properties": {
"document": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
}
}
}'
辞書カスタマイズ設定
設定ファイルパス:
/usr/share/elasticsearch/plugins/japanese-analyzer/config/IKAnalyzer.cfg.xml
設定内容例:
<?xml version="1.0" encoding="UTF-8"?>
<properties>
<comment>IK Analyzer Custom Configuration</comment>
<entry key="ext_dict">user_dict/my_words.dic</entry>
<entry key="ext_stopwords">user_dict/stop_words.dic</entry>
<entry key="remote_ext_dict">http://config-server/dictionary.dic</entry>
<entry key="remote_ext_stopwords">http://config-server/stopwords.dic</entry>
</properties>
ピンイン検索プラグイン
プロジェクトページ:https://github.com/medcl/elasticsearch-analysis-pinyin
手動インストール手順:
cd elasticsearch-root/plugins
mkdir pinyin-search
cd pinyin-search
wget https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v7.10.0/elasticsearch-analysis-pinyin-7.10.0.zip
unzip elasticsearch-analysis-pinyin-7.10.0.zip
自動インストール:
./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v7.10.0/elasticsearch-analysis-pinyin-7.10.0.zip
機能テスト
PUT /chinese_names/
{
"settings" : {
"analysis" : {
"analyzer" : {
"chinese_pinyin" : {
"tokenizer" : "pinyin_tokenizer"
}
},
"tokenizer" : {
"pinyin_tokenizer" : {
"type" : "pinyin",
"keep_separate_first_letter" : false,
"keep_full_pinyin" : true,
"keep_original" : true,
"limit_first_letter_length" : 16,
"lowercase" : true,
"remove_duplicated_term" : true
}
}
}
}
}
Kibanaローカル環境
ダウンロード:https://www.elastic.co/cn/downloads/past-releases#kibana
起動方法:
- Linux: bin/kibana
- Windows: bin\kibana.bat
kibana.yml設定:
server.port: 5601
server.host: "0.0.0.0"
server.name: "dev-kibana"
elasticsearch.hosts: ["http://localhost:9200"]
i18n.locale: "ja-JP"
Logstash設定
ダウンロードURL:https://www.elastic.co/cn/downloads/past-releases#logstash
起動コマンド:
bin/logstash -f ../config/pipeline.conf
設定例:
input {
tcp {
mode => "server"
host => "0.0.0.0"
port => 5044
codec => json_lines
}
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "application-logs-%{+YYYY.MM.dd}"
}
}
アプリケーションログ統合
Maven依存関係:
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>5.2</version>
</dependency>
logback設定例:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProperty scope="context" name="serviceName" source="spring.application.name"/>
<appender name="logstash-output" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>logstash-server:5044</destination>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp/>
<logLevel/>
<message/>
<loggerName/>
</providers>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="logstash-output"/>
</root>
</configuration>
Docker環境構築
Elasticsearchコンテナ
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.10.0
docker run -d --name es-container -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e "ES_JAVA_OPTS=-Xms2g -Xmx2g" \
-v ./es-data:/usr/share/elasticsearch/data \
docker.elastic.co/elasticsearch/elasticsearch:7.10.0
Kibanaコンテナ
docker run -d --name kibana-container -p 5601:5601 \
-e "ELASTICSEARCH_HOSTS=http://es-container:9200" \
docker.elastic.co/kibana/kibana:7.10.0
Logstashコンテナ
docker run -d --name logstash-container \
-v ./logstash-config:/usr/share/logstash/pipeline/ \
docker.elastic.co/logstash/logstash:7.10.0