绊脚石乃是进身之阶。

索引完mapping 拼音搜索搜不出来

Elasticsearch | 作者 Circle | 发布于2018年12月05日 | 阅读数:2608


索引状态.png


搜索1.png


正常搜.png

图一是我设置好hotelname的mapping截图
图二是搜索“如家”拼音的结果
图三是搜索“如家”中文的结果
搜hotelname.pinyin="rujia"也是没有结果的
新手求教
已邀请:

zz_hello

赞同来自:

你拼音分词器的设置是什么样的,是不是大小写的问题,你用analyzerAPI先分析一下rujia和Zen Homes Rujia Hotel的分词结果

zz_hello

赞同来自:

你试试这个能搜索出来吗
PUT mindex
{
"settings": {
"analysis": {
"analyzer": {
"pinyin_analyzer": {
"tokenizer": "my_pinyin"
}
},
"tokenizer": {
"my_pinyin": {
"lowercase": "true",
"keep_original": "true",
"remove_duplicated_term": "true",
"keep_separate_first_letter": "false",
"type": "pinyin",
"limit_first_letter_length": "16",
"keep_full_pinyin": "true"
}
}
}
},
"mappings": {
"doc":{
"properties":{
"name":{
"type":"text",
"fields":{
"pinyin":{
"type":"text",
"analyzer":"pinyin_analyzer",
"term_vector": "with_offsets",
"boost": 10

}
}
}
}
}
}
}

PUT mindex/doc/1
{
"name":"ZEN Rooms Rujia Hotel"
}
PUT mindex/doc/2
{
"name":"如家"
}
PUT mindex/doc/3
{
"name":"如家旅馆"
}

GET /mindex/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"name.pinyin": "rujia"
}
}
]
}
}
}
GET /mindex/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"name.pinyin": "如家"
}
}
]
}
}
}

要回复问题请先登录注册