用Mac进行Elasticsearch 6
我正在考虑引入elasticsearch,但是毫无顾忌地引入了最新版本v6,这是一个刚推出的版本,却找不到任何解释说明…
我会辛苦地进行中文转述并留下笔记。
引入Java8
由于被告知没有安装JDK,于是我尝试安装了Java,但却无法运行在Java 9上。
$ brew cask install java8
Elasticsearch的安装和自动启动设置
$ brew install elasticsearch
$ ln -sfv /usr/local/opt/elasticsearch/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist
网址:http://localhost:9200
如果顺利的话,会在浏览器中返回以下类似的结果。
{
"name" : "5egFqAz",
"cluster_name" : "elasticsearch_makaishi",
"cluster_uuid" : "Yw_85VZrRwigNvlIl0rD4g",
"version" : {
"number" : "6.0.1",
"build_hash" : "601be4a",
"build_date" : "2017-12-04T09:29:09.525Z",
"build_snapshot" : false,
"lucene_version" : "7.0.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
插件的安装
$ cd /usr/local/Cellar/elasticsearch/6.0.1
$ bin/elasticsearch-plugin install analysis-icu
$ bin/elasticsearch-plugin install analysis-kuromoji
创建索引
$ curl -X PUT http://localhost:9200/test
确认索引设置
$ curl -X GET localhost:9200/test/_stats?pretty=true
数据输入
需要指定content-type。
$ curl -H "Content-Type: application/json" -XPOST localhost:9200/index/type -d '{"message": "test message"}'
安装和启动Kibana
$ brew install kibana
$ kibana
网址:http://localhost:5601/
顺利进行时,会出现这样的画面。
关于kuromoji的设置
请从Kibana管理控制台中进行操作。
请选择左侧菜单中的Dev Tools,并复制粘贴以下PUT命令,然后点击执行按钮。
PUT test_jp_map
{
"settings": {
"analysis": {
"filter": {
"synonyms_filter": {
"type": "synonym",
"synonyms": [
"タブホ,たぶ ほ"
]
}
},
"analyzer": {
"jpn-search": {
"type": "custom",
"char_filter": [
"icu_normalizer",
"kuromoji_iteration_mark"
],
"tokenizer": "kuromoji_tokenizer",
"filter": [
"synonyms_filter",
"kuromoji_baseform",
"kuromoji_part_of_speech",
"ja_stop",
"kuromoji_number",
"kuromoji_stemmer"
]
},
"jpn-index": {
"type": "custom",
"char_filter": [
"icu_normalizer",
"kuromoji_iteration_mark"
],
"tokenizer": "kuromoji_tokenizer",
"filter": [
"kuromoji_baseform",
"kuromoji_part_of_speech",
"ja_stop",
"kuromoji_number",
"kuromoji_stemmer"
]
}
}
}
}
}
有关每个设置的含义,可以在使用 Elasticsearch 的配置摘要页面上找到更详细的信息。
测试形态素引擎
请将以下POST文本复制粘贴到Dev Tools并点击“执行”按钮。
POST test_jp_map/_analyze
{
"analyzer": "jpn-search",
"text": "すもももももももものうち"
}
结果
使用Mac版本的Solr来检索日本语形态分析结果的相关链接。