一、创建索引时,自定义拼音分词和ik分词

PUT /my_index
{
"index": {
"analysis": {
"analyzer": {
"ik_pinyin_analyzer": { 自定义分词name
"type": "custom",
"tokenizer": "ik_smart",
"filter": ["my_pinyin", "word_delimiter"]
},
"pinyin_analyzer": {
"type": "custom",
"tokenizer": "ik_max_word",
"filter": ["my_pinyin", "word_delimiter"]
}
},
"filter": {
"my_pinyin": {
"type" : "pinyin",
"keep_separate_first_letter" : false, 启用该选项时,将保留第一个字母分开,例如:刘德华ldh,默认:false,注意:查询结果也许是太模糊,由于长期过频
"keep_full_pinyin" : true, 当启用该选项,例如:刘德华> [ liudehua],默认值:true
"keep_original" : true, 启用此选项时,也将保留原始输入,默认值:false
"limit_first_letter_length" : 16, 设置first_letter结果的最大长度,默认值:16
"lowercase" : true, 小写非中文字母,默认值:true
"remove_duplicated_term" : true 启用此选项后,将删除重复的术语以保存索引,例如:de的de,default:false,注意:位置相关的查询可能会受到影响
}
}
}
}
}

二、创建mapping时,设置字段分词(注:相同索引下建不同的type时,相同字段名属性必须设一样)

POST /my_index/user/_mapping
{
"user": {
"properties": {
"id":{
"type":"integer"
},
"userName": {
"type": "text",
"store": "no",
"term_vector": "with_positions_offsets",
"analyzer": "ik_pinyin_analyzer", 自定义分词器name
"boost": 10,
"fielddata" : true,
"fields": {
"raw": {
"type": "keyword" 设置keyword时,对该字段不进行分析
}
}
},
"reason":{
"type": "text",
"store": "no", 字段store为true,这意味着这个field的数据将会被单独存储。这时候,如果你要求返回field1(store:yes),es会分辨出field1已经被存储了,因此不会从_source中加载,而是从field1的存储块中加载。
"term_vector": "with_positions_offsets",
"analyzer": "ik_pinyin_analyzer",
"boost": 10
}
}
}
}

测试

PUT /my_index/user/1
{
"id":1,
"userName":"刘德华",
"reason":"大帅哥"
} PUT /my_index/user/2
{
"id":2,
"userName":"刘德华",
"reason":"中华人民"
}

不分词查询

GET /my_index/user/_search
{
"query": {
"match": {
"userName.raw": "刘德华"
}
}
} {
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.2876821,
"hits": [
{
"_index": "my_index",
"_type": "user",
"_id": "2",
"_score": 0.2876821,
"_source": {
"id": 2,
"userName": "刘德华",
"reason": "中华人民"
}
},
{
"_index": "my_index",
"_type": "user",
"_id": "1",
"_score": 0.2876821,
"_source": {
"id": 1,
"userName": "刘德华",
"reason": "大帅哥"
}
}
]
}
}

分词查询

GET /my_index/user/_search
{
"query": {
"match": {
"userName": "刘"
}
}
} {
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.31331712,
"hits": [
{
"_index": "my_index",
"_type": "user",
"_id": "2",
"_score": 0.31331712,
"_source": {
"id": 2,
"userName": "刘德华",
"reason": "中华人民"
}
},
{
"_index": "my_index",
"_type": "user",
"_id": "1",
"_score": 0.31331712,
"_source": {
"id": 1,
"userName": "刘德华",
"reason": "大帅哥"
}
}
]
}
}

拼音分词

GET /my_index/user/_search
{
"query": {
"match": {
"reason": "shuai"
}
}
} {
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 3.4884284,
"hits": [
{
"_index": "my_index",
"_type": "user",
"_id": "1",
"_score": 3.4884284,
"_source": {
"id": 1,
"userName": "刘德华",
"reason": "大帅哥"
}
}
]
}
}

分组聚合

GET /my_index/user/_search
{
"size":2,
"query": {
"match": {
"userName": "liu"
}
},
"aggs": {
"group_by_meetingType": {
"terms": {
"field": "userName.raw"
}
}
}
} {
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 3.133171,
"hits": [
{
"_index": "my_index",
"_type": "user",
"_id": "2",
"_score": 3.133171,
"_source": {
"id": 2,
"userName": "刘德华",
"reason": "中华人民"
}
},
{
"_index": "my_index",
"_type": "user",
"_id": "1",
"_score": 3.133171,
"_source": {
"id": 1,
"userName": "刘德华",
"reason": "大帅哥"
}
}
]
},
"aggregations": {
"group_by_meetingType": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "刘德华",
"doc_count": 2
}
]
}
}
}

大神们这些都是个人理解哪里有一样的想法或建议欢迎评论!!!!!!!

Elasticsearch拼音和ik分词器的结合应用的更多相关文章

  1. Elasticsearch下安装ik分词器

    安装ik分词器(必须安装maven) 上传相应jar包 解压到相应目录 unzip elasticsearch-analysis-ik-master.zip(zip包) cp -r elasticse ...

  2. 【ELK】【docker】【elasticsearch】2.使用elasticSearch+kibana+logstash+ik分词器+pinyin分词器+繁简体转化分词器 6.5.4 启动 ELK+logstash概念描述

    官网地址:https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker-cli-run-prod ...

  3. Elasticsearch 7.x - IK分词器插件(ik_smart,ik_max_word)

    一.安装IK分词器 Elasticsearch也需要安装IK分析器以实现对中文更好的分词支持. 去Github下载最新版elasticsearch-ik https://github.com/medc ...

  4. linux(centos 7)下安装elasticsearch 5 的 IK 分词器

    (一)到IK 下载 对应的版本(直接下载release版本,避免mvn打包),下载后是一个zip压缩包 (二)将压缩包上传至elasticsearch 的安装目录下的plugins下,进行解压,运行如 ...

  5. 通过docker安装elasticsearch和安装ik分词器插件及安装kibana

    前提: 已经安装好docker运行环境: 步骤: 1.安装elasticsearch 6.2.2版本,目前最新版是7.2.0,这里之所以选择6.2.2是因为最新的SpringBoot2.1.6默认支持 ...

  6. 【ELK】【docker】【elasticsearch】1. 使用Docker和Elasticsearch+ kibana 5.6.9 搭建全文本搜索引擎应用 集群,安装ik分词器

    系列文章:[建议从第二章开始] [ELK][docker][elasticsearch]1. 使用Docker和Elasticsearch+ kibana 5.6.9 搭建全文本搜索引擎应用 集群,安 ...

  7. docker 部署 elasticsearch + elasticsearch-head + elasticsearch-head跨域问题 + IK分词器

    0.  docker pull 拉取elasticsearch + elasticsearch-head 镜像 1.  启动elasticsearch Docker镜像 docker run -di ...

  8. Docker 下Elasticsearch 的安装 和ik分词器

    (1)docker镜像下载 docker pull elasticsearch:5.6.8 (2)安装es容器 docker run -di --name=changgou_elasticsearch ...

  9. Elasticsearch(ES)分词器的那些事儿

    1. 概述 分词器是Elasticsearch中很重要的一个组件,用来将一段文本分析成一个一个的词,Elasticsearch再根据这些词去做倒排索引. 今天我们就来聊聊分词器的相关知识. 2. 内置 ...

随机推荐

  1. MODIS数据的下载(新地址)

    Modis数据下载方法 1.1打开网址 浏览器输入地址:https://ladsweb.nascom.nasa.gov/search 注:需要一定的等待时间,如果一直打不开,就需要FQ.(网址加载了g ...

  2. 网络协议抓包分析——ARP地址解析协议

    前言 计算机之间可以相互通信的前提是要知道对方的地址,才可以发送信息给其他计算机,就像别人要联系你也得先知道你的电话号码一样.这里的地址因为网络分层的原因就包括IP地址和MAC地址(即网卡地址.硬件地 ...

  3. zookeeper高可用集群搭建

    前提:已经在master01配置好hadoop:在各个slave节点配置好hadoop和zookeeper: (该文是将zookeeper配置在各slave节点上的,其实也可以配置在各master上, ...

  4. Spark内存管理机制

    Spark内存管理机制 Spark 作为一个基于内存的分布式计算引擎,其内存管理模块在整个系统中扮演着非常重要的角色.理解 Spark 内存管理的基本原理,有助于更好地开发 Spark 应用程序和进行 ...

  5. C#窗体越界时鼠标还能回到初始坐标位置

    对窗体加越界限制后,鼠标拖动窗体越界时,窗体不能动,鼠标位置可动,但窗体不再越界时,鼠标位置还能回到鼠标按下时相对窗体的坐标:1.首先创建一个窗体Form1,然后在窗体上拖一个button1按钮(主要 ...

  6. python 实现微信自动回复(自动聊天)

    原文地址(本人):https://blog.csdn.net/a5878989/article/details/54974249 介绍 微信自动回复其实主要就是登录,接收消息,回复消息三个功能,微信没 ...

  7. 3.类和接口_EJ

    第13条: 使类和成员的可访问性最小化 良好的模块设计能隐藏其内部数据和其他实现细节,模块之间只通过它们的API进行通信.java语言提供了许多机制来协助隐藏信息.访问控制机制决定了类.接口和成员的可 ...

  8. HTML5标签选择,图文混排使用dl dt dd

    图文混排,可以使用 dl dt dd(dd 和 dt 是同级,不可以嵌套,没有先后顺序) 1,上面红色部分是标题,可以使用h1里面包含一个span标签,样式一样,所以两个可以一起写. 2,上面黑色部分 ...

  9. loadrunner 脚本录制-录制选项设置HTML-based URL-based Script

    脚本录制-录制选项设置, HTML-based Script与URL-based Script by:授客 QQ:1033553122 Access:Vugen->Tool->Record ...

  10. 【最新】Android使用jenkins全自动构建打包-Windows版本(Android,Jenkins,360加固,Email,QRcode,参数构建,蒲公英)

    Android打包喝咖啡系列(Windows版) 这篇博客主要讲述的内容: 1.windows上部署Jenkins https://jenkins.io 2.基于SVN或Git https://git ...