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. 内置 ...
随机推荐
- Golang中的自动伸缩和自防御设计
Raygun服务由许多活动组件构成,每个组件用于特定的任务.其中一个模块是用Golang编写的,负责对iOS崩溃报告进行处理.简而言之,它接受本机iOS崩溃报告,查找相关的dSYM文件,并生成开发者可 ...
- Redis实现世界杯排行榜功能(实战)
转载请注明出处:https://www.cnblogs.com/wenjunwei/p/9754346.html 需求 前段时间,做了一个世界杯竞猜积分排行榜.对世界杯64场球赛胜负平进行猜测,猜对+ ...
- 解读经典《C#高级编程》第七版 Page38-45.核心C#.Chapter2
前言 控制流是语言中最基础的部分,我们不谈具体的细节,只讲讲一些关键和有趣的点. 01 流控制 条件语句:if, else if, else if语句的使用非常值得细讲,如何是好的使用习惯.有一点非常 ...
- MDK 中 [WEAK] 的作用
简介 __weak 或 [weak] 具有相同的功能,用于定义变量或者函数,常见于定义函数,在 MDK 链接时优先链接定义为非 weak 的函数或变量,如果找不到则再链接 weak 函数. 在STM3 ...
- React Fiber源码分析 第一篇
先附上流程图一张 先由babel编译, 调用reactDOM.render,入参为element, container, callback, 打印出来可以看到element,container,cal ...
- [转]Node.js中koa使用redis数据库
本文转自:https://blog.csdn.net/offbye/article/details/52452322 Redis是一个常用的Nosql数据库,一般用来代替Memcached做缓存服务, ...
- 【转载】Sqlserver强制密码过期导致数据库登录失败
Sqlserver在设置登录账户信息的时候,有个复选框信息会被默认勾上,即强制实施密码策略,默认勾选上的还有强制密码过期.如果勾上了这个强制密码过期后,则你的账户密码在一定时间登录后会提示Sqlser ...
- Asp.net连接数据库的配置方法
1.Sqlserver数据库连接 <connectionStrings> <add name="Conn" connectionString="serv ...
- Intellij idea 项目目录设置 与包的显示创建
1.把目录设置成为层级结构显示.和eclipse类似 去掉flatten Packages前面的勾 在项目中创建多级包的时候要注意,必须在Java下建,并且要全输入才能识别
- H5 video播放视频遇到的问题
我在别的网站上下载了一个mp4格式的视频,加到video标签里可以正常播放, 然后我用FLV自己转成mp4,却提示不支持的格式和mine类型, 后来找到一篇文章 http://jingyan.baid ...