输出的结果为:
{ "tokens" : [ { "token" : "我", "start_offset" : 0, "end_offset" : 1, "type" : "CN_CHAR", "position" : 0 }, { "token" : "是", "start_offset" : 1, "end_offset" : 2, "type" : "CN_CHAR", "position" : 1 }, { "token" : "程序员", "start_offset" : 2, "end_offset" : 5, "type" : "CN_WORD", "position" : 2 }, { "token" : "程序", "start_offset" : 2, "end_offset" : 4, "type" : "CN_WORD", "position" : 3 }, { "token" : "员", "start_offset" : 4, "end_offset" : 5, "type" : "CN_CHAR", "position" : 4 } ] } 6. 修改索引映射mapping 6.1 重建索引删除原有blog1索引
DELETE localhost:9200/blog1创建blog1索引,此时分词器使用ik_max_word
PUT localhost:9200/blog1 { "mappings": { "article": { "properties": { "id": { "type": "long", "store": true, "index":false }, "title": { "type": "text", "store": true, "index":true, "analyzer":"ik_max_word" }, "content": { "type": "text", "store": true, "index":true, "analyzer":"ik_max_word" } } } } }创建文档
POST localhost:9200/blog1/article/1 { "id":1, "title":"ElasticSearch是一个基于Lucene的搜索服务器", "content":"它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。" } 6.2 再次测试queryString查询请求url:
POST localhost:9200/blog1/article/_search请求体:
{ "query": { "query_string": { "default_field": "title", "query": "搜索服务器" } } }postman截图:
将请求体搜索字符串修改为"钢索",再次查询: { "query": { "query_string": { "default_field": "title", "query": "钢索" } } }
postman截图:
6.3 再次测试term测试请求url:
POST localhost:9200/blog1/article/_search请求体:
{ "query": { "term": { "title": "搜索" } } }postman截图: