Skip to content

Instantly share code, notes, and snippets.

@johtani
Last active April 27, 2020 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johtani/25e971ded639e3bea3229ebf861e62be to your computer and use it in GitHub Desktop.
Save johtani/25e971ded639e3bea3229ebf861e62be to your computer and use it in GitHub Desktop.
「辞書の更新についての注意事項」ブログの補足手順など
## 0. インデックスの準備
### 再現可能なようにまず削除
DELETE file_dic_sample
### 辞書ファイルの用意
ファイル名 : custom_dic.txt
配置場所 : ES_PATH_CONF/analyzer/custom_dic.txt
内容
```
グランベリーパーク,グランベリー パーク,グランベリー パーク,カスタム名詞
```
### インデックスの作成(辞書ファイルを設定したKuromoji TokenizerとAnalyzerの設定)
PUT file_dic_sample
{
"settings": {
"index": {
"analysis": {
"tokenizer": {
"kuromoji_user_dict": {
"type": "kuromoji_tokenizer",
"mode": "extended",
"user_dictionary": "analyzer/custom_dic.txt"
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "kuromoji_user_dict"
}
}
}
}
}
}
### 設定の確認
GET file_dic_sample/_analyze
{
"text": "グランベリーパークがオープンしました。",
"analyzer": "my_analyzer",
"explain": true,
"attributes": ["token", "partOfSpeech"]
}
## 1. 更新した辞書ファイルの配布
ファイル名 : custom_dic.txt
配置場所 : ES_PATH_CONF/analyzer/custom_dic.txt
更新後のcustom_dic.txt
```
グランベリーパーク,グランベリー パーク,グランベリー パーク,カスタム名詞
高輪ゲートウェイ,高輪 ゲートウェイ,タカナワ ゲートウェイ,カスタム名詞
```
### 辞書が反映されていないことの確認
GET file_dic_sample/_analyze
{
"text": "高輪ゲートウェイがオープンしました。",
"analyzer": "my_analyzer",
"explain": true,
"attributes": ["token", "partOfSpeech"]
}
## 2. インデックスクローズ
POST file_dic_sample/_close
## 3. インデックスオープン
POST file_dic_sample/_open
### 辞書が反映されているかチェック
GET file_dic_sample/_analyze
{
"text": "高輪ゲートウェイがオープンしました。",
"analyzer": "my_analyzer",
"explain": true,
"attributes": ["token", "partOfSpeech"]
}
## 4. 再インデックス
POST file_dic_sample/_update_by_query
## 0. インデックスの準備
### 再現可能なようにまず削除
DELETE custom_dic_sample
### インデックスの作成(辞書を設定したKuromoji TokenizerとAnalyzerの設定)
PUT custom_dic_sample
{
"settings": {
"index": {
"analysis": {
"tokenizer": {
"kuromoji_user_dict": {
"type": "kuromoji_tokenizer",
"mode": "extended",
"user_dictionary_rules": [
"グランベリーパーク,グランベリー パーク,グランベリー パーク,カスタム名詞"]
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "kuromoji_user_dict"
}
}
}
}
}
}
### 設定の確認
GET custom_dic_sample/_analyze
{
"text": "グランベリーパークがオープンしました。",
"analyzer": "my_analyzer",
"explain": true,
"attributes": ["token", "partOfSpeech"]
}
## 1. インデックスクローズ
POST custom_dic_sample/_close
## 2. 辞書の更新(インデックス設定の更新)
PUT custom_dic_sample/_settings
{
"index": {
"analysis": {
"tokenizer": {
"kuromoji_user_dict": {
"type": "kuromoji_tokenizer",
"mode": "extended",
"user_dictionary_rules": [
"グランベリーパーク,グランベリー パーク,グランベリー パーク,カスタム名詞",
"高輪ゲートウェイ,高輪 ゲートウェイ,タカナワ ゲートウェイ,カスタム名詞"]
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "kuromoji_user_dict"
}
}
}
}
}
## 3. インデックスオープン
POST custom_dic_sample/_open
### 辞書が反映されているかチェック
GET custom_dic_sample/_analyze
{
"text": "高輪ゲートウェイがオープンしました。",
"analyzer": "my_analyzer",
"explain": true,
"attributes": ["token", "partOfSpeech"]
}
## 4. 再インデックス
POST custom_dic_sample/_update_by_query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment