您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
elasticSearch指定索引默认搜索分析器
发布时间:2021-09-11 13:38:28编辑:雪饮阅读()
在前面我们有指定过索引的默认分析器,那么除了默认分析器之外,还有就是索引的默认搜索分析器也可以指定的。
如:
请求正文:
{
"settings": {
"analysis": {
"analyzer": {
"default": {
"type": "simple"
},
"default_search": {
"type": "whitespace"
}
}
}
}
}
响应正文:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "my-index-000001"
}
此时我们可以创建一个用于测试的文档
请求正文:
{
"message":"An apple", "description":"ICSE", "street":"West End",
"state":"UP", "zip":"250002", "location":[28.9926174, 77.692485], "fees":3500,
"tags":["fully computerized"], "rating":"4.5"
}
响应正文:
{
"_index": "my-index-000001",
"_type": "_doc",
"_id": "4",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
可以看到这里message中包含单词apple。
那么有如下查询请求:
请求正文:
{
"query": {
"match": {
"message": {
"query": "Apple"
}
}
}
}
响应正文:
{
"took": 1010,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
}
}
这里为什么查不到呢?因为文档中是apple而不是Apple。当然这个是个人都知道。
那么还有更深一层就是说这里索引的默认分析器是simple,simple拆词出来都是所有术语都小写。
但是我们搜索过程中使用的索引也就是上面我们配置的default_search,我们用的是whitespace分析器,而whitespace分析器会将搜索字串拆分为区分大小写的令牌。那么所以这里搜索Apple仍旧是以Apple去和simple拆出来的全部小写的,而Apple中是包含有大写字面a的,自然就是匹配不到了。
关键字词:elasticSearch,默认,搜索,分析器,索引
相关文章
- elasticSearch如何调用测试索引目前配置的分析器
- elasticSearch为索引指定默认分析器
- elasticSearch映射参数boost
- elasticSearch创建指定字段的搜索分析器(空白分析仪与
- elasticSearch为查询指定搜索分析器(stop分析器)
- elasticSearch创建指定字段分析器
- elasticSearch创建custom分析器char_filter,tokenizer
- elasticSearch创建custom分析器搭载html条带字符过滤
- elasticSearch内置分析器(停用词的使用)
- elasticSearch索引中创建自定义分析器(custom)及按分