1.测试Elasticsearch的分词

Elasticsearch有多种分词器(参考:https://www.jianshu.com/p/d57935ba514b)

Set the shape to semi-transparent by calling set_trans(5)

(1)standard analyzer:标准分词器(默认是这种)
set,the,shape,to,semi,transparent by,calling,set_trans,5

(2)simple analyzer:简单分词器
set, the, shape, to, semi, transparent, by, calling, set, trans

(3)whitespace analyzer:空白分词器。大小写,下划线等都不会转换
Set, the, shape, to, semi-transparent, by, calling, set_trans(5)

(4)language analyzer:(特定语言分词器,比如说English英语分瓷器)
set, shape, semi, transpar, call, set_tran, 5

2.为Elasticsearch的index设置分词

这样就将这个index里面的所有type的分词设置成了simple

PUT my_index
{
"settings": {
"analysis": {
"analyzer": {"default":{"type":"simple"}}
}
}
}
标准分词器 : standard analyzer
http://localhost:9200/_analyze?analyzer=standard&pretty=true&text=test测试

分词结果

{
"tokens" : [
{
"token" : "test",
"start_offset" : 0,
"end_offset" : 4,
"type" : "<ALPHANUM>",
"position" : 0
},
{
"token" : "测",
"start_offset" : 4,
"end_offset" : 5,
"type" : "<IDEOGRAPHIC>",
"position" : 1
},
{
"token" : "试",
"start_offset" : 5,
"end_offset" : 6,
"type" : "<IDEOGRAPHIC>",
"position" : 2
}
]
}

简单分词器 : simple analyzer

http://localhost:9200/_analyze?analyzer=simple&pretty=true&text=test_测试

结果

{
"tokens" : [
{
"token" : "test",
"start_offset" : 0,
"end_offset" : 4,
"type" : "word",
"position" : 0
},
{
"token" : "测试",
"start_offset" : 5,
"end_offset" : 7,
"type" : "word",
"position" : 1
}
]
}

IK分词器 : ik_max_word analyzer ik_smart analyzer

首先需要安装

https://github.com/medcl/elasticsearch-analysis-ik

下zip包,然后使用install plugin进行安装,我机器上的es版本是5.6.10,所以安装的就是5.6.10

./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.6.10/elasticsearch-analysis-ik-5.6.10.zip

然后重新启动Elasticsearch就可以了

进行测试

http://localhost:9200/_analyze?analyzer=ik_max_word&pretty=true&text=test_tes_te测试

结果

{
"tokens" : [
{
"token" : "test_tes_te",
"start_offset" : 0,
"end_offset" : 11,
"type" : "LETTER",
"position" : 0
},
{
"token" : "test",
"start_offset" : 0,
"end_offset" : 4,
"type" : "ENGLISH",
"position" : 1
},
{
"token" : "tes",
"start_offset" : 5,
"end_offset" : 8,
"type" : "ENGLISH",
"position" : 2
},
{
"token" : "te",
"start_offset" : 9,
"end_offset" : 11,
"type" : "ENGLISH",
"position" : 3
},
{
"token" : "测试",
"start_offset" : 11,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 4
}
]
}

Elasticsearch学习笔记——分词的更多相关文章

  1. elasticsearch学习笔记——相关插件和使用场景

    logstash-input-jdbc学习 ES(elasticsearch缩写)的一大优点就是开源,插件众多.所以扩展起来非常的方便,这也造成了它的生态系统越来越强大.这种开源分享的思想真是与天朝格 ...

  2. ElasticSearch学习笔记(超详细)

    文章目录 初识ElasticSearch 什么是ElasticSearch ElasticSearch特点 ElasticSearch用途 ElasticSearch底层实现 ElasticSearc ...

  3. Elasticsearch学习笔记一

    Elasticsearch Elasticsearch(以下简称ES)是一款Java语言开发的基于Lucene的高效全文搜索引擎.它提供了一个分布式多用户能力的基于RESTful web接口的全文搜索 ...

  4. ElasticSearch学习笔记(一)-- 查询索引分词

    # 查看所有索引 GET _cat/indices # 创建一个索引 PUT /test_index # 插入一条数据(指定id)PUT /test_index/doc/ { "userna ...

  5. elasticsearch学习笔记-倒排索引以及中文分词

    我们使用数据库的时候,如果查询条件太复杂,则会涉及到很多问题 1.无法维护,各种嵌套查询,各种复杂的查询,想要优化都无从下手 2.效率低下,一般语句复杂了之后,比如使用or,like %,,%查询之后 ...

  6. Elasticsearch学习笔记

    Why Elasticsearch? 由于需要提升项目的搜索质量,最近研究了一下Elasticsearch,一款非常优秀的分布式搜索程序.最开始的一些笔记放到github,这里只是归纳总结一下. 首先 ...

  7. 2018/2/13 ElasticSearch学习笔记三 自动映射以及创建自动映射模版,ElasticSearch聚合查询

    终于把这些命令全敲了一遍,话说ELK技术栈L和K我今天花了一下午全部搞定,学完后还都是花式玩那种...E却学了四天(当然主要是因为之前上班一直没时间学,还有安装服务时出现的各种error真是让我扎心了 ...

  8. 2018/2/11 ELK技术栈之ElasticSearch学习笔记二

    终于有时间记录一下最近学习的知识了,其实除了写下的这些还有很多很多,但懒得一一写下了: ElasticSearch添加修改删除原理:ElasticSearch的倒排索引和文档一旦生成就不允许修改(其实 ...

  9. 【原】无脑操作:ElasticSearch学习笔记(01)

    开篇来自于经典的“保安的哲学三问”(你是谁,在哪儿,要干嘛) 问题一.ElasticSearch是什么?有什么用处? 答:截至2018年12月28日,从ElasticSearch官网(https:// ...

随机推荐

  1. incomplete type is not allowed ofstream

    错误: incomplete type is not allowed 解决方案: #include<fstream>

  2. 近年NOIP考点与主要做法

  3. chrome浏览器下载内容存放位置

    点击: 或者直接快捷键 ctrl +J 打开下载的资料在[设置]中可将浏览器设置成默认浏览器,更换下载内容的存放位置:给一个提示,本人未曾修改下载的存放位置,是用户/Administrator/Dow ...

  4. 百度杯 ctf 九月场---Text

    一看题目发现善于查资料就行了,那估计就是以前的漏洞,需要百度搜一下,果然是海洋cms的漏洞!这个漏洞是前台getshell漏洞,seach漏洞,该漏洞成因在于search.php没有对用户输入内容进行 ...

  5. django生产环节部署

    在linux下安装mysql yum install mysql-server mysql -u root(安装完后,你的root账户是没有密码的.所以你可以直接使用这条命令,就可以登陆控制台了) 如 ...

  6. CentOS 7配置成网关服务器

    其实在Linux下配置网关服务器很简单,如果配置好之后出现无法访问外网的情况,那么可以排查以下情况: 1.防火墙和iptables的服务关掉(firewalld.iptables) 2.清空iptab ...

  7. CentOS使用Ubuntu的start-stop-daemon来启动守护进程

    在CentOS下使用守护进程启动有/etc/init.d/functions文件下的daemon方法,但如果要使用Ubuntu下的start-stop-daemon方法也可以实现. 安装如下: # 下 ...

  8. 解析 ViewTreeObserver 源码(上)

    主要内容:ViewTreeObserver 是被用来注册监听视图树的观察者,在视图树发生全局改变时将收到通知.本文从 ViewTreeObserver 源码出发,带你剖析 ViewTreeObserv ...

  9. adminlte.js-页面模版

    html页面 使用cdn加速. <!DOCTYPE html> <html lang="en"> <head> <title>Tes ...

  10. AWStats日志分析系统

    1.什么是AWStats AWStats是一款功能强大且功能强大的免费工具,可以图形方式生成高级Web,流媒体,ftp或邮件服务器统计信息.此日志分析器用作CGI或命令行, 并在几个图形网页中显示您的 ...