您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
elasticSearch为查询指定搜索分析器(stop分析器)
发布时间:2021-09-10 16:20:20编辑:雪饮阅读()
ElasticSearch中查询我们一般有如下使用方式。
那么假定有这样的一个数据:
请求正文:
{
"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": 4,
"result": "updated",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 3,
"_primary_term": 1
}
我们这里要查这个message的数据,则一般查询有如:
请求正文:
{
"query": {
"match": {
"message": {
"query": "an"
}
}
}
}
响应正文:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.22108284,
"hits": [
{
"_index": "my-index-000001",
"_type": "_doc",
"_id": "4",
"_score": 0.22108284,
"_source": {
"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"
}
}
]
}
}
这里主要是通过查询单词”an”,在message字段中去搜索,看看有哪些文档中有message字段并且其值中包含单词”an”。那么这样的查询肯定就是没有问题的,上面这个文档肯定就是命中的。
但是如果你将上面这个请求正文修改如:
{
"query": {
"match": {
"message": {
"query": "an",
"analyzer": "stop"
}
}
}
}
这里新增指定了使用stop分析器,该stop分析仪是像simple仪,而且还支持去除停止词。
那么接下来响应结果如:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
}
}
为什么现在命中文档中就不包含上面我们创建的这个文档了呢?
这是因为我们指定了message字段在进行查询时候使用了stop分析器,而stop分析器会去除停止词,而搜索的关键字”on”又正好是属于停止词的,所以上面创建的这个文档中message中的”on”被去除了(虽然只是在当前运行时中去除了,但这样本次请求就不会有结果了),所以就搜索不到了。
关键字词:elasticSearch,查询,指定搜索分析器,stop,分析器
相关文章
- elasticSearch创建指定字段分析器
- elasticSearch创建custom分析器char_filter,tokenizer
- elasticSearch创建custom分析器搭载html条带字符过滤
- elasticSearch内置分析器(停用词的使用)
- elasticSearch索引中创建自定义分析器(custom)及按分
- elasticSearch测试分析仪-标准标记器与ASCII码折叠标
- elasticSearch测试分析仪
- elasticSearch类型的自动创建、动态映射与cluster.rou
- elasticSearch集群重新路由
- elasticSearch禁用自动分片分配(cluster.routing.allo