我在做AWS弹性搜索。在我的项目中,我遇到了一种情况,在我的报告中,我必须搜索像“冠病毒”这样的关键词。
但结果应该包含“冠状病毒”、“冠状病毒”、“冠状病毒”等关键词。
请指导我如何构建我的查询DSL。
注意:使用PHP语言。
感谢你的帮助。
//Amit
发布于 2020-04-10 14:58:15
您需要使用瓦形令牌滤波器
一种类型为shingle的令牌过滤器,它从令牌流中构造片瓦(令牌n克)。换句话说,它将令牌的组合创建为单个令牌。例如,“请将这句话分成小块”可以标记为“请分割”、“分割”、“这句话”、“句子分成”和“分片”。
映射
PUT index91
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"filter": [
"lowercase",
"shingle_filter"
]
}
},
"filter": {
"shingle_filter": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 3,
"output_unigrams": true,
"token_separator": ""
}
}
}
},
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}数据:
POST index91/_doc
{
"title":"corona virus"
}查询:
GET index91/_search
{
"query": {
"match": {
"title": "coronavirus"
}
}
}结果:
"hits" : [
{
"_index" : "index91",
"_type" : "_doc",
"_id" : "gNmUZHEBrJsHVOidaoU_",
"_score" : 0.9438393,
"_source" : {
"title" : "corona virus"
}
}它也适用于“日冕”、“日冕病毒”、“病毒”。
https://stackoverflow.com/questions/61142369
复制相似问题