【发布时间】:2020-11-15 17:10:33
【问题描述】:
我正在使用 elasticsearch 并提出了这样一个问题。 我定义了一个 analyzer 类型为 shingle 并创建了一个映射。
代码如下:
{
"settings": {
"analysis": {
"char_filter": {
"icons": {
"type": "mapping",
"mappings_path": "analysis/char_filter.txt"
}
},
"filter": {
"synonym_filter": {
"type": "synonym",
"synonyms_path": "analysis/synonym_filter.txt"
},
"shingle_filter":{
"type":"shingle",
"max_shingle_size": 2,
"min_shingle_size": 2,
"output_unigrams": true,
"token_separator": ""
}
},
"analyzer": {
"my_analyzer": {
"filter": [
"lowercase",
"synonym_filter",
"shingle_filter"
],
"char_filter": [
"icons"
],
"tokenizer": "standard"
}
}
}
},
"mappings": {
"type-0": {
"properties": {
"text": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
}
然后,我将一个文档放入索引中。
{
"text":"hello"
}
之后我开始这样搜索:
{
"query":{
"match":{
"text":{
"query":"hell world",
"fuzziness":1
}
}
}
}
但它什么都不匹配。 然后我将查询更改为:
{
"query":{
"match":{
"text":{
"query":"world hell",
"fuzziness":1
}
}
}
}
此请求获取文档。
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.21576157,
"hits": [
{
"_index": "index-001",
"_type": "product",
"_id": "1",
"_score": 0.21576157,
"_source": {
"text": "hello"
}
}
]
}
}
我的 elasticsearch 版本是 6.2.4
谁能告诉我原因?
【问题讨论】:
标签: elasticsearch