ElasticSearch教程——自定义分词器(转学习使用)

一、分词器

Elasticsearch中,内置了很多分词器(analyzers),例如standard(标准分词器)、english(英文分词)和chinese(中文分词),默认是standard.

standard tokenizer:以单词边界进行切分
standard token filter:什么都不做
lowercase token filter:将所有字母转换为小写
stop token filer(默认被禁用):移除停用词,比如a the it等等

 

二、修改分词器设置

启用english,停用词token filter

PUT /my_index
{"settings": {"analysis": {"analyzer": {"es_std":{"type":"standard","stopwords":"_english_"}}}}
}

三、标准分词测试代码

GET /my_index/_analyze
{"analyzer": "standard","text":"a dog is in the house"
}

结果:

{"tokens": [{"token": "a","start_offset": 0,"end_offset": 1,"type": "<ALPHANUM>","position": 0},{"token": "dog","start_offset": 2,"end_offset": 5,"type": "<ALPHANUM>","position": 1},{"token": "is","start_offset": 6,"end_offset": 8,"type": "<ALPHANUM>","position": 2},{"token": "in","start_offset": 9,"end_offset": 11,"type": "<ALPHANUM>","position": 3},{"token": "the","start_offset": 12,"end_offset": 15,"type": "<ALPHANUM>","position": 4},{"token": "house","start_offset": 16,"end_offset": 21,"type": "<ALPHANUM>","position": 5}]
}

四、设置的英文分词测试代码

GET /my_index/_analyze
{"analyzer": "es_std","text":"a dog is in the house"}

结果:

{"tokens": [{"token": "dog","start_offset": 2,"end_offset": 5,"type": "<ALPHANUM>","position": 1},{"token": "house","start_offset": 16,"end_offset": 21,"type": "<ALPHANUM>","position": 5}]
}

五、自定义分词器

PUT /my_index
{"settings": {"analysis": {"char_filter": {"&_to_and": {"type": "mapping","mappings": ["&=> and"]}},"filter": {"my_stopwords": {"type": "stop","stopwords": ["the", "a"]}},"analyzer": {"my_analyzer": {"type": "custom","char_filter": ["html_strip", "&_to_and"],"tokenizer": "standard","filter": ["lowercase", "my_stopwords"]}}}}
}

测试:

GET /my_index/_analyze
{"text": "tom&jerry are a friend in the house, <a>, HAHA!!","analyzer": "my_analyzer"
}

结果:

{"tokens": [{"token": "tomandjerry","start_offset": 0,"end_offset": 9,"type": "<ALPHANUM>","position": 0},{"token": "are","start_offset": 10,"end_offset": 13,"type": "<ALPHANUM>","position": 1},{"token": "friend","start_offset": 16,"end_offset": 22,"type": "<ALPHANUM>","position": 3},{"token": "in","start_offset": 23,"end_offset": 25,"type": "<ALPHANUM>","position": 4},{"token": "house","start_offset": 30,"end_offset": 35,"type": "<ALPHANUM>","position": 6},{"token": "haha","start_offset": 42,"end_offset": 46,"type": "<ALPHANUM>","position": 7}]
}

六、type中的使用

PUT /my_index/_mapping/my_type
{"properties": {"content": {"type": "text","analyzer": "my_analyzer"}}
}

 

转载于:https://www.cnblogs.com/yfb918/p/10718712.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/277927.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

使用Azure Serverless来开发Teams App

Azure Function可以说比较早期的一个serverless服务&#xff0c;随着这些年云服务的大行其道&#xff0c;Serverless在概念越来越火&#xff0c;什么叫serverless&#xff1f; Serverless computing (or serverless for short), is an execution model where the cloud provide…

Angular之RouterModule的forRoot与forChild

Angular 提供了一种方式来把服务提供商从模块中分离出来&#xff0c;以便模块既可以带着 providers 被根模块导入&#xff0c;也可以不带 providers 被子模块导入。 区别&#xff1a; forRoot creates a module that contains all the directives, the given routes, and the r…

关于 someone could be eavesdropping on you right now (man-in-the-middle attack) ssh的解决办法

关于 someone could be eavesdropping on you right now (man-in-the-middle attack) ssh的解决办法 记录工作中遇到的问题 someone could be eavesdropping on you right now (man-in-the-middle attack) ssh  由于远程机器或者重组或者更新了ssh server导致本地记录的验证信…

使用AzureFunction开发最简单的Teams Outgoing Webhook

上篇文章讲了teams app的serverless架构&#xff0c;这篇主要讲如何真正使用Azure Function来开发一个最最简单的Teams Outgoing Webhook。 我们先登入azure的portal&#xff0c;创建一个azure function。我这里创建了一个名字叫outgoing-webhook的azure function。完成后如下…

Java 基础 之 标识符

www.verejava.com/?id1699254… /* 标识符的命名规则: 1. 是以字母&#xff0c;数字&#xff0c;下滑线_和美元符号$ 组成 2. 不能以数字开头 3. 区分大小写 4. 不能是java的保留关键字 5. 最好是见名思意 */ public class Identifier {public static void main(String[] args…

Ubuntu宿主机与VMware中其他系统虚拟机的互通

Ubuntu做宿主机&#xff0c;VMware中创建Windows10&#xff0c;并且通过三种模式实现两系统互通&#xff0c;其实并非是件难事。在有线网卡未接网线的环境下&#xff0c;关闭两系统防火墙&#xff0c;基本遵从下文便可实现。 转载&#xff1a;https://note.youdao.com/ynotesha…

使用Azure轻松实现Teams App的全球合规性

我在之前的一篇博客里面讲了合规性对于我们Teams app是非常重要的&#xff0c;因为office365平台就是面向全世界用户的&#xff0c;我们开发的teams app一旦发布后&#xff0c;立刻就会有各国各地区的用户来进行安装使用&#xff0c;所以符合用户所在地区的要求是非常重要的。 …

【php复习之】php创建数组的几种方式

1、array()函数 1.1无key值 $arrarray(1,2,3,4); 1.2键值对 $arrarray( name>myj,age>18,phone>1888888888);1.3空数组 $arrarray(); 2、compact()函数 compact函数可以把变量转换为数组。 $a aaa;$b bbb;$c ccc;$arr3 compact(a,b,c);输出&#xff1a;{"a&q…

ADC知识(2)——直流参数(输入电压参考,参考电流输入,积分非线性误差,差分非线性误差)...

目录 四、 输入参考电压范围 五、 参考电流 六、 非线性问题 差分非线性误差 积分非线性 四、 输入参考电压范围 大多数数据手册中&#xff0c;将它定义为一个特定的参考电压值&#xff0c;通常这个电压作为 此转换器最常用的参考电压。在参考输入电压…

LuckyDraw app使用CosmosDB的成本分析

我在以前的博客里说过我的LuckyDraw app在数据存储方面使用的是 Azure Table Storage&#xff0c;当时选择这个的原因是成本考虑&#xff0c;因为它实在是便宜&#xff0c;对于我这种个人开发维护的免费的teams app来说&#xff0c;成本是一个很重要的考量点。 当然&#xff0…

React 重温之 组件生命周期

生命周期 任何事物都不会凭空产生&#xff0c;也不会无故消亡。一个事物从产生到消亡经理的各个阶段&#xff0c;我们称之为 生命周期。 具体到我们的前端组件上来&#xff0c;一个组件的生命周期可以大体分为创建、更新、销毁这个三个阶段。 本文主要介绍React 的组件生命周期…

迁移聊天记录到Teams

有一些朋友问我teams是否支持将其他平台/系统里的聊天记录迁移某个channel里&#xff0c;答案是肯定的&#xff0c;teams团队在去年年中的时候就提供了这个功能。这个功能是通过graph api来完成的&#xff0c;我们今天就来看看如何迁移聊天记录到teams里。 首先&#xff0c;我…

leetcode-191-Number of 1 Bits

题目描述&#xff1a; Write a function that takes an unsigned integer and returns the number of 1 bits it has (also known as the Hamming weight). Example 1: Input: 11 Output: 3 Explanation: Integer 11 has binary representation 000000000000000000000000000010…

androidsdk里的android.bat和uiautomatorview.bat启动就闪退问题

进入D:\androidsdk\tools文件夹&#xff1a; 使用编辑文件工具&#xff1a; rem Check we have a valid Java.exe in the path.set java_execall lib\find_java.bat 替换成下列代码&#xff1a; rem Check we have a valid Java.exe in the path.set java_exeC:\Program Files\…

10 个优质的 Laravel 扩展推荐

这里有 10 个用来搭建 Laravel 应用的包 为何会创建这个包的列表&#xff1f;因为我是一个「比较懒」的开发者&#xff0c;在脸书上是多个 Laravel 小组的成员。平日遇到最多的问题就是开发是需要用那些包。我很懒所以我不想每次都从头开始搞这些东东。 为何此文没有包括管理包…

Teams AppId, InstallationId 和 ExternalId 的区别

大家如果看teams的 graph api 开发文档&#xff0c;可能会把 app id, installation id 和 external id 搞混&#xff0c;我自己一开始的时候就有点被搞晕了&#xff0c;再加上app manifest里面的 id 和 bot id&#xff0c;基本就彻底晕掉了。 那我们今天这篇文章就来讲讲这几种…

osi参考模型(开放系统互连参考模型)

自互联网诞生以来&#xff0c;随着网络飞速发展&#xff0c;用户迫切要求能在不同体系结构的网络空间交换信息&#xff0c;使得不同的网络能够互联起来。 国际化标准组织&#xff08;International Organization for Standardization&#xff0c;即ISO&#xff09;从1977年开始…

Java:反射+泛型:获取类型参数的实例

2019独角兽企业重金招聘Python工程师标准>>> 场景描述&#xff1a; 我需要开发四个页面&#xff0c;每个页面都是只涉及增删改查的基本逻辑。 最简单的写法&#xff1a; 创建四个接口A,B,C,D&#xff0c;每个接口中都声明了增删改查四个方法,完全一致 public Map<…

servlet(1)

servlet类分级&#xff1a; 1.ServletConfig接口类&#xff1a;理解为读取servlet配置的类&#xff0c;里面有四个抽象方法如下&#xff1a; ①getServletName:获取servlet在web.xml中的名字 ②getServletContext&#xff1a;获取Servlet上下文&#xff0c;相当于web项目管理所…

如何在 Apple Silicon (M1) 上开发 Teams App

apple 在几个月前发布了自家的芯片 M1&#xff0c;由于将多核cpu&#xff0c;多核gpu&#xff0c;神经网络运算&#xff0c;内存和其他一切处理部件高度整合在一起&#xff0c;大大提高数据传输速度。发布后好评如潮&#xff0c;我也没有忍住&#xff0c;入手了一台最低配的mac…