站长工具 站长之家,北京免费网站建设模板,如何创建个人网站模板,学网站论坛分词器的内部组成到底是什么#xff0c;以及内置分词器的介绍 1、什么是分词器 切分词语#xff0c;normalization#xff08;提升recall召回率#xff09; 给你一段句子#xff0c;然后将这段句子拆分成一个一个的单个的单词#xff0c;同时对每个单词进行normalization…分词器的内部组成到底是什么以及内置分词器的介绍 1、什么是分词器 切分词语normalization提升recall召回率 给你一段句子然后将这段句子拆分成一个一个的单个的单词同时对每个单词进行normalization时态转换单复数转换分词器recall召回率搜索的时候增加能够搜索到的结果的数量 character filter在一段文本进行分词之前先进行预处理比如说最常见的就是过滤html标签spanhellospan -- hello -- andIyou -- I and youtokenizer分词hello you and me -- hello, you, and, metoken filterlowercasestop wordsynonymomdogs -- dogliked -- likeTom -- toma/the/an -- 干掉mother -- momsmall -- little 一个分词器很重要将一段文本进行各种处理最后处理好的结果才会拿去建立倒排索引 2、内置分词器的介绍 Set the shape to semi-transparent by calling set_trans(5) standard analyzerset, the, shape, to, semi, transparent, by, calling, set_trans, 5默认的是standard大小写转换 括号去除 等等simple analyzerset, the, shape, to, semi, transparent, by, calling, set, transwhitespace analyzerSet, the, shape, to, semi-transparent, by, calling, set_trans(5)language analyzer特定的语言的分词器比如说english英语分词器set, shape, semi, transpar, call, set_tran, 5 _query string的分词以及mapping引入案例遗留问题的大揭秘 1、query string分词 query string必须以和index建立时相同的analyzer进行分词query string对exact value和full text的区别对待 dateexact value_allfull text 比如我们有一个document其中有一个field包含的value是hello you and me建立倒排索引我们要搜索这个document对应的index搜索文本是hell me这个搜索文本就是query stringquery string默认情况下es会使用它对应的field建立倒排索引时相同的分词器去进行分词分词和normalization只有这样才能实现正确的搜索 我们建立倒排索引的时候将dogs -- dog结果你搜索的时候还是一个dogs那不就搜索不到了吗所以搜索的时候那个dogs也必须变成dog才行。才能搜索到。 知识点不同类型的field可能有的就是full text有的就是exact value post_datedateexact value_allfull text分词normalization 3、测试分词器 GET /_analyze{ analyzer: standard, text: Text to analyze} mapping的核心数据类型以及dynamic mapping 1、核心的数据类型 stringbyteshortintegerlongfloatdoublebooleandate 2、dynamic mapping true or false -- boolean123 -- long123.45 -- double2017-01-01 -- datehello world -- string/text 3、查看mapping GET /index/_mapping/type 手动建立和修改mapping以及定制string类型数据是否分词 1、如何建立索引 analyzednot_analyzedno 2、修改mapping 只能创建index时手动建立mapping或者新增field mapping但是不能update field mapping PUT /website{ mappings:{ article:{ properties:{ author_id:{ type:long }, title:{ type:text, analyzer:english }, content:{ type:text }, post_date:{ type:date }, publisher_id:{ type:text, index:not_analyzed } } } }} PUT /website{ mappings:{ article:{ properties:{ author_id:{ type:text } } } }} { error: { root_cause: [ { type: index_already_exists_exception, reason: index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists, index_uuid: co1dgJ-uTYGBEEOOL8GsQQ, index: website } ], type: index_already_exists_exception, reason: index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists, index_uuid: co1dgJ-uTYGBEEOOL8GsQQ, index: website }, status: 400} PUT /website/_mapping/article{ properties : { new_field : { type : string, index: not_analyzed } }} 3、测试mapping GET /website/_analyze{ field: content, text: my-dogs } GET website/_analyze{ field: new_field, text: my dogs} { error: { root_cause: [ { type: remote_transport_exception, reason: [4onsTYV][127.0.0.1:9300][indices:admin/analyze[s]] } ], type: illegal_argument_exception, reason: Cant process field [new_field], Analysis requests are only supported on tokenized fields }, status: 400} _filter与query深入对比解密相关度性能 1、filter与query对比大解密 filter仅仅只是按照搜索条件过滤出需要的数据而已不计算任何相关度分数对相关度没有任何影响query会去计算每个document相对于搜索条件的相关度并按照相关度进行排序 一般来说如果你是在进行搜索需要将最匹配搜索条件的数据先返回那么用query如果你只是要根据一些条件筛选出一部分数据不关注其排序那么用filter除非是你的这些搜索条件你希望越符合这些搜索条件的document越排在前面返回那么这些搜索条件要放在query中如果你不希望一些搜索条件来影响你的document排序那么就放在filter中即可 2、filter与query性能 filter不需要计算相关度分数不需要按照相关度分数进行排序同时还有内置的自动cache最常使用filter的数据query相反要计算相关度分数按照分数进行排序而且无法cache结果 Text vs. keyword ElasticSearch 5.0以后string类型有重大变更移除了string类型string字段被拆分成两种新的数据类型: text用于全文搜索的,而keyword用于关键词搜索。 ElasticSearch对字符串拥有两种完全不同的搜索方式. 你可以按照整个文本进行匹配, 即关键词搜索(keyword search), 也可以按单个字符匹配, 即全文搜索(full-text search). 对ElasticSearch稍有了解的人都知道, 前者的字符串被称为not-analyzed字符, 而后者被称作analyzed字符串。 Text会分词然后进行索引 支持模糊、精确查询 不支持聚合 keyword不进行分词直接索引 支持模糊、精确查询 支持聚合 text用于全文搜索的, 而keyword用于关键词搜索. 如果想做类似于sql中的like查询可定义为keyword并使用通配符wildcard方式查询。转载于:https://www.cnblogs.com/jiahaoJAVA/p/11009392.html