Created
January 28, 2016 09:28
-
-
Save nakamura244/a1481e1e351ae0a6198d to your computer and use it in GitHub Desktop.
elasticsearchのセットアップして日本語の全文検索を試す ref: http://qiita.com/nakamura-tsuyoshi/items/993a4f87bcef2be59db5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[elasticsearch-2.x] | |
name=Elasticsearch repository for 2.x packages | |
baseurl=http://packages.elastic.co/elasticsearch/2.x/centos | |
gpgcheck=1 | |
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch | |
enabled=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------------------------- Index ----------------------------------- | |
index : | |
analysis : | |
analyzer : | |
ja : | |
type : custom | |
tokenizer : ja_tokenizer | |
char_filter : [ | |
html_strip, | |
kuromoji_iteration_mark | |
] | |
filter : [ | |
lowercase, | |
cjk_width, | |
katakana_stemmer, | |
kuromoji_part_of_speech | |
] | |
ja_ngram : | |
type : custom | |
tokenizer : ngram_ja_tokenizer | |
char_filter : [html_strip] | |
filter : [ | |
cjk_width, | |
lowercase | |
] | |
tokenizer : | |
ja_tokenizer : | |
type : kuromoji_tokenizer | |
mode : search | |
user_dictionary : /etc/elasticsearch/userdict_ja.txt | |
ngram_ja_tokenizer : | |
type : nGram | |
min_gram : 2 | |
max_gram : 3 | |
token_chars : [letter, digit] | |
filter : | |
katakana_stemmer : | |
type : kuromoji_stemmer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd /usr/share/elasticsearch/ | |
bin/plugin install analysis-kuromoji |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XGET 'localhost:9200/projects03-20160111/_analyze?analyzer=ja&pretty' -d 'こんにちわ' | |
{ | |
"tokens" : [ { | |
"token" : "こんにちわ", | |
"start_offset" : 0, | |
"end_offset" : 5, | |
"type" : "word", | |
"position" : 0 | |
} ] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XGET 'localhost:9200/projects03-20160111/project/_search?pretty' -d' | |
> { | |
> "query":{"match":{"title_ngram":"こんに"}} | |
> }' | |
{ | |
"took" : 2, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 1, | |
"successful" : 1, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 0.13287117, | |
"hits" : [ { | |
"_index" : "projects03-20160111", | |
"_type" : "project", | |
"_id" : "1", | |
"_score" : 0.13287117, | |
"_source": | |
{ | |
"project_id": 1, | |
"title" : "川島さんこんにちわ", | |
"title_ngram" : "川島さんこんにちわ", | |
"detail" : "内容内容内容内容", | |
"detail_ngram" : "内容内容内容内容", | |
"update_time" : "2016-01-28 22:22:22" | |
} | |
} ] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin/plugin install lmenezes/elasticsearch-kopf/v2.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@xxx ~]# ll /usr/share/elasticsearch/plugins/ | |
合計 8 | |
drwxr-xr-x. 2 root root 4096 1月 12 00:08 analysis-kuromoji | |
drwxr-xr-x. 8 root root 4096 1月 12 00:33 kopf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPUT localhost:9200/_template/projects03 -d ' | |
{ | |
"order": 0, | |
"template": "projects03-*", | |
"settings": { | |
"index": { | |
"number_of_shards": "1", | |
"number_of_replicas": "0" | |
} | |
}, | |
"mappings": { | |
"project": { | |
"_source": { | |
"enabled": true | |
}, | |
"_all": { | |
"analyzer": "ja", | |
"enabled": true | |
}, | |
"properties": { | |
"update_time": { | |
"format": "YYYY-MM-dd HH:mm:ss", | |
"type": "date" | |
}, | |
"project_id": { | |
"index": "not_analyzed", | |
"type": "string" | |
}, | |
"detail": { | |
"analyzer": "ja", | |
"type": "string" | |
}, | |
"suggest": { | |
"search_analyzer": "ja", | |
"analyzer": "ja", | |
"type": "completion" | |
}, | |
"detail_ngram": { | |
"analyzer": "ja_ngram", | |
"type": "string" | |
}, | |
"title": { | |
"analyzer": "ja", | |
"type": "string" | |
}, | |
"title_ngram": { | |
"analyzer": "ja_ngram", | |
"type": "string" | |
} | |
} | |
} | |
}, | |
"aliases": { | |
} | |
}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@xxx ~]# /etc/init.d/elasticsearch restart | |
Restarting elasticsearch (via systemctl): [ OK ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST http://localhost:9200/projects03-20160111/project/<id> -d ' | |
{ | |
"project_id": 1, | |
"title" : "川島さんこんにちわ", | |
"title_ngram" : "川島さんこんにちわ", | |
"detail" : "内容内容内容内容", | |
"detail_ngram" : "内容内容内容内容", | |
"update_time" : "2016-01-28 22:22:22" | |
} | |
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@xxx ~]# curl -XGET 'localhost:9200/projects03-20160111/project/_search?pretty' -d' | |
> { | |
> "query":{"match":{"title":"こんに"}} | |
> }' | |
{ | |
"took" : 1, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 1, | |
"successful" : 1, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 0, | |
"max_score" : null, | |
"hits" : [ ] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XGET 'localhost:9200/projects03-20160111/project/_search?pretty' -d' | |
> { | |
> "query":{"match":{"title":"こんにちわ"}} | |
> }' | |
{ | |
"took" : 1, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 1, | |
"successful" : 1, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 0.15342641, | |
"hits" : [ { | |
"_index" : "projects03-20160111", | |
"_type" : "project", | |
"_id" : "1", | |
"_score" : 0.15342641, | |
"_source": | |
{ | |
"project_id": 1, | |
"title" : "川島さんこんにちわ", | |
"title_ngram" : "川島さんこんにちわ", | |
"detail" : "内容内容内容内容", | |
"detail_ngram" : "内容内容内容内容", | |
"update_time" : "2016-01-28 22:22:22" | |
} | |
} ] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment