install es and plugins
elasticsearch-6.4.1 download
plugin:
analysis-smartcn (eg: ./bin/elasticsearch-plugin install analysis-smartcn)
ik
then start es: bin/elasticsearch
surfing
验证分词器是否生效
1 | curl --request POST \ |
hibernate-search-elasticsearch
config index and mapping
- 设置analyzer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24curl --request PUT \
--url http://localhost:9200/com.wework.entity.company -d \
'{
"index": {
"analysis": {
"analyzer": {
"pinyin_analyzer": {
"tokenizer": "my_pinyin"
}
},
"tokenizer": {
"my_pinyin": {
"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
}
}
}
}
}' - 设置mapping
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23curl --request PUT \
--url http://localhost:9200/com.wework.entity.company/_mapping/com.wework.entity.Company -d \
'{
"properties": {
"name": {
"type": "text",
"analyzer": "ik_smart",
"fields": {
"pinyin": {
"type": "text",
"store": false,
"term_vector": "with_offsets",
"analyzer": "pinyin_analyzer",
"boost": 10
},
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}' - 查看mapping
1
2curl --request GET \
--url http://localhost:9200/com.wework.entity.user/_mapping \ - 搜索
1
2
3
4
5
6
7
8
9
10
11
12curl --request POST \
--url 'http://localhost:9200/com.wework.entity.user/_search?pretty=' -d \
'{
"query": {
"match": {
"name.pinyin": "xiao明"
}
},
"from": 0,
"size": 10,
"sort": ["_score"]
}'