一、创建索引时,自定义拼音分词和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. ClickHouse之访问权限控制

    研究ClickHouse也有几周了,今天来和大家说说ClickHouse的访问权限是怎么做的,ClickHouse不像MySQL那样,直接创建用户,而是需要在配置文件里面添加用户,一个简单的例子如下: ...

  2. 机器学习中数据清洗&预处理

    数据预处理是建立机器学习模型的第一步,对最终结果有决定性的作用:如果你的数据集没有完成数据清洗和预处理,那么你的模型很可能也不会有效 第一步,导入数据 进行学习的第一步,我们需要将数据导入程序以进行下 ...

  3. 【Vue.js】vue项目目录作用

    1. build文件夹:打包配置的文件夹 1.1  webpack.base.conf.js :打包的核心配置 1.2  build.js:构建生产版本,项目开发完成之后,通过build.js打包(加 ...

  4. μC/OS-II 任务堆栈的初始化

    任务堆栈的作用 应用程序在创建一个新任务的时候,必须把在系统启动这个任务时 CPU 各寄存器所需要的初始数据(任务指针.任务堆栈指针.程序状态字等等),事先存放在任务的堆栈中,以备任务切换等操作时调用 ...

  5. Spring Cloud Stream消费失败后的处理策略(三):使用DLQ队列(RabbitMQ)

    应用场景 前两天我们已经介绍了两种Spring Cloud Stream对消息失败的处理策略: 自动重试:对于一些因环境原因(如:网络抖动等不稳定因素)引发的问题可以起到比较好的作用,提高消息处理的成 ...

  6. git中的忽略配置文件中没有忽略该文件,却提交不到服务器上。

    解决方法:在被忽略项目上单击右键

  7. [android] 插入一条记录到系统短信应用里

    谷歌市场上有这些应用,模拟短信,原理就是把数据插入到短信应用的数据库里 获取ContentResolver对象,通过getContentResolver()方法 调用resolver对象的insert ...

  8. spring_03ApplicationContext三种经常用到的实现

    1.ClassPathXmlApplicationContext从类路径加载 ApplicationContext ac=new ClassPathXmlApplicationContext(&quo ...

  9. react学习(二)之通信篇

    react性能提升原理:虚拟DOM react把真是的DOM tree,转化成virtual DOM,每次数据更新后,重新计算virtual DOM并与上一次的作对比,然后对发生改变的部分进行批量更新 ...

  10. LeetCode | HouseCode 算法题

    题目: You are a professional robber planning to rob houses along a street. Each house has a certain am ...