一、创建索引时,自定义拼音分词和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. 开发“todolist“”项目及其自己的感悟

    一,项目题目: 实现“todolist项目” 该项目主要可以练习js操控dom事件,事件触发之间的逻辑关系,以及如何写入缓存,获取缓存.固定. 二,todolist简介 ToDoList是一款非常优秀 ...

  2. 绝对路径的表示方式为什么是"/usr"而不是"//usr"

    今天闲逛贴吧,竟然看到有个人问绝对路径的表示方式为什么不是//usr/local而是/usr/local.原文: 我想99%的人都没想过这个问题,都理所当然的认为:它不就是根"/" ...

  3. 关于VUE首屏加载过长的优化,VUE项目开发优化

    1. 按需引入UI组件 当下市面上流行的UI组件基本都支持按需加载,本文以Element UI为例: (1)     新建一个elementUI.js文件 (2)     访问地址找到按需引入方式的说 ...

  4. Redis学习笔记(3)-XShell连接CentOSMini,并安装Redis

    使用XShell远程连接CentOSMini 点击download下载XShell5.0. 下载之后安装.配置XShell. 配置XShell前的准备 打开VM,启动CentOSMini.CentOS ...

  5. [转]Node.JS使用Sequelize操作MySQL

    Sequelize官方文档  https://sequelize.readthedocs.io/en/latest/ 本文转自:https://www.jianshu.com/p/797e10fe23 ...

  6. C#线程同步--限量使用

    问题抽象:当某一资源同一时刻允许一定数量的线程使用的时候,需要有个机制来阻塞多余的线程,直到资源再次变得可用.线程同步方案:Semaphore.SemaphoreSlim.CountdownEvent ...

  7. [PHP] PHP多进程处理tcp连接

    <?php if(($sock = socket_create(AF_INET, SOCK_STREAM, 0)) < 0) { echo "failed to create s ...

  8. Get与Post的主要区别

    这里附一篇自己的简短理解 get相对于post更不安全,虽然都可以加密 get的参数会显示在浏览器地址栏中,而post的参数不会显示在浏览器地址栏中: 使用post提交的页面在点击[刷新]按钮的时候浏 ...

  9. 洛谷P3245 [HNOI2016]大数(莫队)

    题意 题目链接 Sol 莫队板子题.. 维护出每个位置开始的字符串\(mod P\)的结果,记为\(S_i\) 两个位置\(l, r\)满足条件当且仅当\(S_l - S_r = 0\),也就是\(S ...

  10. [DOM基础]offsetHeight,clientHeight,scrollHeight,innerHeight,outerHeight等属性的解释

    由于经常搞混这几个属性,所以查找资料总结一下,方便以后翻出来温习. 一.偏移量-以offset开头的 1.offsetHeight:元素在垂直方向上占用的空间大小,像素.包括元素的高度.可见的水平滚动 ...