Elasticsearch拼音和ik分词器的结合应用
一、创建索引时,自定义拼音分词和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, 启用该选项时,将保留第一个字母分开,例如:刘德华
>l
,d
,h
,默认:false,注意:查询结果也许是太模糊,由于长期过频
"keep_full_pinyin" : true, 当启用该选项,例如:刘德华
> [liu
,de
,hua
],默认值: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分词器的结合应用的更多相关文章
- Elasticsearch下安装ik分词器
安装ik分词器(必须安装maven) 上传相应jar包 解压到相应目录 unzip elasticsearch-analysis-ik-master.zip(zip包) cp -r elasticse ...
- 【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 ...
- Elasticsearch 7.x - IK分词器插件(ik_smart,ik_max_word)
一.安装IK分词器 Elasticsearch也需要安装IK分析器以实现对中文更好的分词支持. 去Github下载最新版elasticsearch-ik https://github.com/medc ...
- linux(centos 7)下安装elasticsearch 5 的 IK 分词器
(一)到IK 下载 对应的版本(直接下载release版本,避免mvn打包),下载后是一个zip压缩包 (二)将压缩包上传至elasticsearch 的安装目录下的plugins下,进行解压,运行如 ...
- 通过docker安装elasticsearch和安装ik分词器插件及安装kibana
前提: 已经安装好docker运行环境: 步骤: 1.安装elasticsearch 6.2.2版本,目前最新版是7.2.0,这里之所以选择6.2.2是因为最新的SpringBoot2.1.6默认支持 ...
- 【ELK】【docker】【elasticsearch】1. 使用Docker和Elasticsearch+ kibana 5.6.9 搭建全文本搜索引擎应用 集群,安装ik分词器
系列文章:[建议从第二章开始] [ELK][docker][elasticsearch]1. 使用Docker和Elasticsearch+ kibana 5.6.9 搭建全文本搜索引擎应用 集群,安 ...
- docker 部署 elasticsearch + elasticsearch-head + elasticsearch-head跨域问题 + IK分词器
0. docker pull 拉取elasticsearch + elasticsearch-head 镜像 1. 启动elasticsearch Docker镜像 docker run -di ...
- Docker 下Elasticsearch 的安装 和ik分词器
(1)docker镜像下载 docker pull elasticsearch:5.6.8 (2)安装es容器 docker run -di --name=changgou_elasticsearch ...
- Elasticsearch(ES)分词器的那些事儿
1. 概述 分词器是Elasticsearch中很重要的一个组件,用来将一段文本分析成一个一个的词,Elasticsearch再根据这些词去做倒排索引. 今天我们就来聊聊分词器的相关知识. 2. 内置 ...
随机推荐
- gradle 自定义插件 下载配置文件
1.新建Gradle项目: 2.建立src/main/groovy目录,并添加如下代码: ConfigPlugin.groovy package com.wemall.config import or ...
- Keras 构建DNN 对用户名检测判断是否为非法用户名(从数据预处理到模型在线预测)
一. 数据集的准备与预处理 1 . 收集dataset (大量用户名--包含正常用户名与非法用户名) 包含两个txt文件 legal_name.txt ilegal_name.txt. 如下图所 ...
- FFmpeg中overlay滤镜用法-水印及画中画
本文为作者原创,转载请注明出处:https://www.cnblogs.com/leisure_chn/p/10434209.html 1. overlay技术简介 overlay技术又称视频叠加技术 ...
- 再也不用被this苦恼了
前端编程对于this再熟悉不过了,今日来个老调重弹温故知新,肯定有很多大佬已经完全吃透了this原理,敬请出门左拐.对于理解this似懂非懂的同学可以借鉴一波 1.this描述 this指的是当前执行 ...
- shell中$后加引号有什么用($"string"和$'string')
bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html 有些时候在某些服务管理脚本中看到$"$string& ...
- C#通过调用WinApi打印PDF文档类,服务器PDF打印、IIS PDF打印
其他网站下载来的类,可以用于Winform.Asp.Net,用于服务器端PDF或其他文件打印. 直接上代码: using System; using System.Collections.Generi ...
- EF C# ToPagedList方法 The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must ……
报错信息:The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' ...
- element框架中表格的筛选功能使用说明(转载)
一.element框架中表格的筛选功能使用说明 转载:https://blog.csdn.net/liangxhblog/article/details/80513030 在element ui 框架 ...
- 买or不买?如何测试博彩公司赔率是否合理?
世界杯期间,烧烤店.酒吧都热闹起来了,柔柔我的朋友圈也热闹起来了,有酱紫的: 还有酱紫的: 然后还有酱紫的: 酱紫的: 当然天台也是一如既然的热闹: 似乎人人都在输钱,那真正的赢家在哪里呢?博彩业的真 ...
- eclipse安装阿里编码规约插件
点击帮助,Install New Software... 地址为https://p3c.alibaba.com/plugin/eclipse/update 然后选择安装, 一路next即可