主要是看到太多人写的不全,或者不能满足。
–索引库属性构建
#############################
sms_course/_settings PUT
{
"index": {
"analysis": {
"analyzer": {
"ik_pinyin_analyzer": {
"type": "custom",
"tokenizer": "ik_smart",
"filter": [
"my_pinyin",
"word_delimiter"
]
}
},
"filter": {
"my_pinyin": {
"type": "pinyin",
"keep_first_letter": true,
"limit_first_letter_length": 16,
"keep_full_pinyin": true,
"keep_joined_full_pinyin": true,
"keep_none_chinese_in_first_letter": true,
"keep_none_chinese_in_joined_full_pinyin": true,
"none_chinese_pinyin_tokenize": false,
"keep_original": true,
"ignore_pinyin_offset": false
}
}
}
}
}
#############################
sms_course/course/_mapping POST
{
"course": {
"properties": {
"id": {
"type": "keyword"
},
"title": {
"type": "text",
"analyzer": "ik_pinyin_analyzer",
"fields": {
"pinyin": {
"type": "text",
"store": false,
"term_vector": "with_offsets",
"analyzer": "ik_pinyin_analyzer",
"boost": 10,
"index_options": "docs"
}
}
},
"filed_suggester": {
"type": "completion",
"search_analyzer": "ik_pinyin_analyzer",
"analyzer": "ik_pinyin_analyzer",
"max_input_length": 50,
"preserve_separators": true,
"preserve_position_increments": true
},
"info": {
"type": "join",
"relations": {
"md_product": "sl_customer_character_order_list"
}
}
}
}
}
属性含义和设置地址:
https://github.com/longshanw/elasticsearch-analysis-pinyin
##########
kibana
DELETE /sms_course/course/_analyze
DELETE /sms_teacher/teacher/l3WtD1vIRiG7t_Epzp7oGw
DELETE /sms_course
DELETE /sms_teacher
#查询所有
GET _search
{
“query”: {
“match_all”: {}
}
}
#定义2个库 测试和添加数据
GET /sms_course/course/_search
{
}
GET /sms_teacher/teacher/_search
{
}
#测试pinyin
GET _analyze
{
“analyzer”: “pinyin”,
“text”: “刘德华”
}
GET /sms_teacher/teacher/_search
{
“query”: {
“match”: {
“title”:“刘德华”
}
}
}
GET /sms_course/course/_search
{
“suggest”: {
“my-suggest”:{
“prefix”:“ni”,
“completion”: {
“field”: “filed_suggester”
}
}
}
}
#添加数据测试
GET /sms_teacher/teacher
{
“id”: “666666”,
“title”: “花似有情非有情,水似无意非无意。”,
“filed_suggester”:“花似有情非有情,水似无意非无意。”
}
GET /sms_course/course
{
“id”: “666666”,
“title”: “我往事悠然壹笑間”,
“filed_suggester”:“我往事悠然壹笑間”
}
#停止集群分片分配
PUT /_cluster/settings
{
“transient” : {
“cluster.routing.allocation.enable” : “none”
}
}
#重启分片分配
PUT /_cluster/settings
{
“transient” : {
“cluster.routing.allocation.enable” : “all”
}
}