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. 内置 ...
随机推荐
- Linux软件包管理之源码包、脚本安装包
目录 1.源码包和RPM包的区别 RPM包和源码包默认安装位置: 由于安装位置不同带来的影响 2.源码包安装 ①.安装准备 ②.安装注意事项 ③.安装源码包 3.源码包卸载 4.脚本安装包 5.总结 ...
- Perl文件、目录常用操作
注意,这些操作的对象是文件名(相对路径/绝对路径),而非文件/目录句柄,句柄只是perl和文件系统中文件的关联通道,而非实体对象. 创建文件 在unix类操作系统中有一个touch命令可以非常方便的创 ...
- Python作用域详述
作用域是指变量的生效范围,例如本地变量.全局变量描述的就是不同的生效范围. python的变量作用域的规则非常简单,可以说是所有语言中最直观.最容易理解的作用域. 在开始介绍作用域之前,先抛一个问题: ...
- 【转载】 Sqlserver查看数据库死锁的SQL语句
在Sqlsever数据库中,有时候操作数据库过程中会进行锁表操作,在锁表操作的过程中,有时候会出现死锁的情况出现,这时候可以使用SQL语句来查询数据库死锁情况,主要通过系统数据库Master数据库来查 ...
- 基于mvc三层架构和ajax技术实现最简单的文件上传
前台页面提交文件 <!DOCTYPE html> <html><head> <meta name="viewport" content=& ...
- C#通过窗体属性缩小一定尺寸时,无法再缩小窗体尺寸问题
问题:通过窗体属性缩小窗体尺寸时,发现改变到一定大小时无法再缩小.条件:在代码中设置窗体的尺寸由窗体属性里设置的宽高决定,但实际通过窗体属性设置窗体大小,一定大小时无法再缩小,那是因为我们没有把窗体属 ...
- Contest2089 - 湖南多校对抗赛(2015.05.31) Swipe(csu1648)
Problem E: Swipe Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 100 Solved: 15[Submit][Status][Web ...
- Java基础IO流(三)字符流
字符流: 文本和文本文件: java的文本(char)是16位无符号整数,是字符的unicode编码(双字节编码)文件是byte byte byte....的数据序列,而文本文件是文本(char)序列 ...
- js canvas 转动时钟实例
源码:https://pan.baidu.com/s/1R12MwZYs0OJw3OWKsc8WNw 样本:http://js.zhuamimi.cn/shizhong/ 我的百度经验:https:/ ...
- 洛谷P2421 [NOI2002]荒岛野人(扩展欧几里得)
题目背景 原 A-B数对(增强版)参见P1102 题目描述 克里特岛以野人群居而著称.岛上有排列成环行的M个山洞.这些山洞顺时针编号为1,2,…,M.岛上住着N个野人,一开始依次住在山洞C1,C2,… ...