模糊多重匹配未按预期弹性搜索工作



我正试图在添加模糊性的情况下编写搜索查询。(弹性搜索7.12(

{
"query": {
"multi_match": {
"query": "airl recl",
"fields": [
"tags",
"display_text",
"display_subtext"
],
"type" : "most_fields",
"operator": "and",
"fuzziness": "AUTO:4,6",
"prefix_length" :2 
}
}

}

我插入了带有";airtel充值";价值观我也使用边缘n克(1:50(为上面给定的3个字段和空间分析器。

  1. 如果我用airl->它运行良好,通过airtel关键字获得结果
  2. 如果我用recl搜索->它运行良好充值关键字的结果
  3. 但当我用";空气再循环;在查询中,没有得到任何结果

空间分析器:

"words_with_spaces_analyzer" : {
"filter" : [
"lowercase",
"asciifolding"
],
"type" : "custom",
"tokenizer" : "words_with_space"
}
},
"tokenizer" : {
"words_with_space" : {
"pattern" : "([a-zA-Z0-9.-]+[\s]*)",
"type" : "pattern",
"group" : "0"
}
}
},

映射

"display_text": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
},
"analyzer": "edge_nGram_analyzer",
"search_analyzer": "words_with_spaces_analyzer"
}

有人能帮助我理解为什么上面给出的查询对多令牌输入表现出这种行为,而如果两个令牌都单独运行,那么这两个查询都会输出吗?

您需要使用一个空白分析器,作为search_analyzer。这将把搜索项"airl recl"分解为airlrecl。然后,将对这些单独的令牌执行搜索

添加一个具有索引映射、搜索查询和搜索结果的工作示例

索引映射:

{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 50,
"token_chars": [
"letter",
"digit"
]
}
}
},
"max_ngram_diff": 50
},
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "my_analyzer",
"search_analyzer": "whitespace"
}
}
}
}

指数数据:

{
"name": "airtel recharge"
}

搜索查询:

{
"query": {
"multi_match": {
"query": "airl recl",
"fields": [
"name"
],
"type": "most_fields",
"operator": "and",
"fuzziness": "AUTO:4,6",
"prefix_length": 2
}
}
}

搜索结果:

"hits": [
{
"_index": "67702617",
"_type": "_doc",
"_id": "1",
"_score": 0.22729424,
"_source": {
"name": "airtel recharge"
}
}
]

最新更新