ES搜索下拉框查询,联词提示(Suggestion)

主要是看到太多人写的不全,或者不能满足。
–索引库属性构建

  1. 支持集群多索引库+多条件分组+模糊匹配+下拉联想词 (同时支持中文+拼音分词进行混合查询+识别简体和繁体切换)。 支持 IK +
    pinyin (需要在服务安装插件,安装就不说了,启动必须自己用户,记得关闭集群分片在启动)
#############################
 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"
        }
      }
    }
  }
}
  1. 用kibana 也可以,这里用elasticsearch-head插件。 注
    :设置属性,需要把当前的索引库先关闭,设置完成在打开添加数据测试。

属性含义和设置地址:
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”
}
}

在这里插入图片描述
在这里插入图片描述
主要是对于服务以及代码实现,索引库的完善配置参考。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值