本章分两部分拼音分词和智能提醒
1、拼音分词
直接参考:https://github.com/medcl/elasticsearch-analysis-pinyin
参数的说明,github已经说的很清楚了:
2、智能提醒
参考:https://blog.csdn.net/baifanwudi/article/details/88662561
先建含有自定义拼音分词的索引
PUT /steven_piny/
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"pinyin_analyzer": {
"tokenizer": "my_pinyin"
}
},
"tokenizer": {
"my_pinyin": {
"type": "pinyin",
"keep_first_letter":true,
"keep_separate_first_letter": true,
"keep_full_pinyin": true,
"keep_original": true,
"limit_first_letter_length": 16,
"lowercase": true
}
}
}
}
},
"mappings": {
"properties": {
"station_name": {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"s-pinyin": {
"type": "completion",
"analyzer": "pinyin_analyzer"
}
}
},
"station_code": {
"type": "completion"
}
}
}
}
当然以上也可以分开建setting和mapping。
加入数据:
PUT /steven_piny/_doc/1
{
"station_code": "VAP",
"station_name": "北京北"
}
PUT /steven_piny/_doc/2
{
"station_code": "BOP",
"station_name": "北京东"
}
PUT /steven_piny/_doc/3
{
"station_code": "GGQ",
"station_name": "广州南"
}
PUT /steven_piny/_doc/4
{
"station_code": "SHH",
"station_name": "上海"
}
查询
POST /steven_piny/_search
{
"suggest":{
"text":"bj",
"code-suggest" : {
"completion" : {
"field" : "station_code"
}
},
"pinyin-suggest" : {
"completion" : {
"field" : "station_name.s-pinyin"
}
}
}
}
--------------------------------------------------
POST /steven_piny/_search
{
"suggest":{
"text":"广",
"code-suggest" : {
"completion" : {
"field" : "station_code"
}
},
"pinyin-suggest" : {
"completion" : {
"field" : "station_name.s-pinyin"
}
}
}
}