es拼音搜索首字母显示

我的es安装拼音插件 elasticsearch-analysis-pinyin 。
现在搜索“luo”会出现。
"大红罗" "东罗园" "簸箩巷" "东罗圈胡同" "罗马嘉园东区" "罗马嘉园西区"
如何让其中的“罗”字开头的排在前面
 
已邀请:

leveret

赞同来自:

真的很不活跃,回复真的很少!!!!!

medcl - Elasticsearch资深爱好者

赞同来自:

你的拼音分词是如何配置的,麻烦贴一下,你如果希望保持顺序,那么你就不用对拼音进行分词。

gyhyq

赞同来自:

curl -XPUT http://XXXXX:9200/comidx_py_wz_qy/_settings -d'
{
"index" : {
        "analysis" : {
            "analyzer" : {
                "pinyin_analyzer" : {
                    "tokenizer" : "my_pinyin",
                    "filter" : ["word_delimiter","nGram"]
                }
            },
            "tokenizer" : {
                "my_pinyin" : {
                    "type" : "pinyin",
                    "first_letter" : "prefix",
                    "padding_char" : " "
                }
            }
        }
    }
}'

"estateName": {     "type": "multi_field",
             "fields": {
             "estateName": {
                                  "type": "string",
                                  "store": "no",
                                  "term_vector": "with_positions_offsets",
                                  "analyzer": "pinyin_analyzer",
                                  "boost": 10
                      },
                          "primitive": {
                             "type": "string",
                             "store": "yes",
                             "analyzer": "keyword"
                      }
                }
             },
 

medcl - Elasticsearch资深爱好者

赞同来自:

这个配置:"filter" : ["word_delimiter","nGram"]
就是先把拼音拆开,再Ngram切,所以会出现你说的问题。
curl -XPUT http://XXXXX:9200/comidx_py_wz_qy/_settings -d'
{
"index" : {
"analysis" : {
"analyzer" : {
"pinyin_analyzer_1" : {
"tokenizer" : "my_pinyin"
}
},
"tokenizer" : {
"my_pinyin" : {
"type" : "pinyin",
"first_letter" : "none",
"padding_char" : ""
}
}
}
}
}'

mapping:
"estateName": {     "type": "multi_field",
"fields": {
"prefix": {
"type": "string",
"store": "no",
"term_vector": "with_positions_offsets",
"analyzer": "pinyin_analyzer_1",
"boost": 10
},
"primitive": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
}
}
},

查询的时候,使用prefix query:
?q=estateName.prefix:luo*

 

gyhyq

赞同来自:

已经配置好了,十分感谢

lxjeanse

赞同来自:

@medcl,按照这个配置,我这里搜索的结果是只有"罗马嘉园东区" "罗马嘉园西区",如果需要显示其他结果,而"罗马嘉园东区" "罗马嘉园西区"又要排在前面,有什么办法吗?多谢了

要回复问题请先登录注册