数据库-Elasticsearch进阶学习笔记(集群、故障、扩容、简繁体、拼音等
-- 创建Elasticsearch索引
PUT /imdb
{
"settings": {
"index": {
"number_of_shards": 3,
"number_of_replicas": 2
}
},
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "ik_smart"
},
"title_pinyin": {
"type": "text",
"fields": {
"pinyin": {
"type": "text",
"analyzer": "pinyin_analyzer"
}
}
}
}
}
}
-- 自定义分析器设置,以支持拼音搜索
PUT /imdb/_settings
{
"analysis": {
"analyzer": {
"pinyin_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "pinyin",
"keep_original": true,
"keep_separate_first_letter": false,
"keep_full_pinyin": true,
"keep_joined_full_pinyin": true,
"keep_none_chinese": false,
"keep_none_chinese_in_joined_full_pinyin": true,
"keep_none_chinese_in_separate_first_letter": true,
"keep_none_chinese_in_joined_first_letter": true,
"keep_none_chinese_in_original": true
}
}
}
}
这个代码示例展示了如何创建一个Elasticsearch索引,并定义了字段的映射和自定义分析器设置,以支持对拼音的搜索。它使用了Elasticsearch的IK分析器扩展来进行智能分词,并定义了一个自定义分析器来处理拼音。这对于需要进行中文内容搜索和处理的开发者来说是一个很好的参考。
评论已关闭