IK分词器和ElasticSearch集成使用

“position”: 2

},

{

“token”: “中文”,

“start_offset”: 13,

“end_offset”: 15,

“type”: “CN_WORD”,

“position”: 3

},

{

“token”: “分词”,

“start_offset”: 15,

“end_offset”: 17,

“type”: “CN_WORD”,

“position”: 4

},

{

“token”: “工具包”,

“start_offset”: 17,

“end_offset”: 20,

“type”: “CN_WORD”,

“position”: 5

}

]

}

2)最细切分:在浏览器地址栏输入地址

请求:GET http://localhost:9200/_analyze?analyzer=ik_max_word&pretty=true&text=IKAnalyzer是一个中文分词工具包

{

“tokens”: [

{

“token”: “ikanalyzer”,

“start_offset”: 0,

“end_offset”: 10,

“type”: “ENGLISH”,

“position”: 0

},

{

“token”: “是”,

“start_offset”: 10,

“end_offset”: 11,

“type”: “CN_CHAR”,

“position”: 1

},

{

“token”: “一个”,

“start_offset”: 11,

“end_offset”: 13,

“type”: “CN_WORD”,

“position”: 2

},

{

“token”: “一”,

“start_offset”: 11,

“end_offset”: 12,

“type”: “TYPE_CNUM”,

“position”: 3

},

{

“token”: “个中”,

“start_offset”: 12,

“end_offset”: 14,

“type”: “CN_WORD”,

“position”: 4

},

{

“token”: “个”,

“start_offset”: 12,

“end_offset”: 13,

“type”: “COUNT”,

“position”: 5

},

{

“token”: “中文”,

“start_offset”: 13,

“end_offset”: 15,

“type”: “CN_WORD”,

“position”: 6

},

{

“token”: “分词”,

“start_offset”: 15,

“end_offset”: 17,

“type”: “CN_WORD”,

“position”: 7

},

{

“token”: “工具包”,

“start_offset”: 17,

“end_offset”: 20,

“type”: “CN_WORD”,

“position”: 8

},

{

“token”: “工具”,

“start_offset”: 17,

“end_offset”: 19,

“type”: “CN_WORD”,

“position”: 9

},

{

“token”: “包”,

“start_offset”: 19,

“end_offset”: 20,

“type”: “CN_CHAR”,

“position”: 10

}

]

}

修改索引映射mapping:

1. 创建blog索引,分词器使用ik_max_word

请求:PUT https://localhost:9200/blog

{

“mappings”: {

“hello”: {

“properties”: {

“id”: {

“type”: “long”,

“store”: true,

“index”:“not_analyzed”

},

“title”: {

“type”: “text”,

“store”: true,

“index”:“analyzed”,

“analyzer”:“ik_max_word”

},

“content”: {

“type”: “text”,

“store”: true,

“index”:“analyzed”,

“analyzer”:“ik_max_word”

}

}

}

}

}

在postman中测试结果:

在这里插入图片描述

2. 创建文档

请求:POST https://localhost:9200/blog/article/1

{

“id”:1,

“title”:“IK分词器测试”,

“content”:“IK提供了两个分词算法ik_smart 和 ik_max_word,其中 ik_smart 为最少切分,ik_max_word为最细粒度划分”

}

{

“id”:2,

“title”:“ElasticSearch是一个基于Lucene的搜索服务器”,

“content”:“它提供了一个分布式多用户能力的全文搜索引擎,基于RESTfulweb接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。”

}

{

“id”:3,

“title”:“ElasticSearch概述”,

“content”:“Elasticsearch是面向文档(document oriented)的,这意味着它可以存储整个对象或文档(document)。然而它不仅仅是存储,还会索引(index)每个文档的内容使之可以被搜索。在Elasticsearch中,你可以对文档(而非成行成列的数据)进行索引、搜索、排序、过滤。”

}

3. term测试查询

请求:POST localhost:9200/blog/hello/_search

请求体:

{

“query”:{

“term”:{

“content”:“搜索”

}

}

}

在postman中测试:

在这里插入图片描述

在这里插入图片描述

4. 测试queryString查询

请求:POST localhost:9200/blog/hello/_search

请求体:

{

“query”:{

“query_string”:{

“default_field”: “content”,

“query”:“搜索服务器”

最后

针对最近很多人都在面试,我这边也整理了相当多的面试专题资料,也有其他大厂的面经。希望可以帮助到大家。

image

上述的面试题答案都整理成文档笔记。 也还整理了一些面试资料&最新2021收集的一些大厂的面试真题(都整理成文档,小部分截图)

image

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
POST localhost:9200/blog/hello/_search

请求体:

{

“query”:{

“query_string”:{

“default_field”: “content”,

“query”:“搜索服务器”

最后

针对最近很多人都在面试,我这边也整理了相当多的面试专题资料,也有其他大厂的面经。希望可以帮助到大家。

[外链图片转存中…(img-0NGHS14l-1718731787460)]

上述的面试题答案都整理成文档笔记。 也还整理了一些面试资料&最新2021收集的一些大厂的面试真题(都整理成文档,小部分截图)

[外链图片转存中…(img-hEy9MzQh-1718731787461)]

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值