【发布时间】:2015-09-04 04:35:27
【问题描述】:
弹性搜索 1.6
我想索引包含连字符的文本,例如 U-12、U-17、WU-12、t-shirt...,并能够使用“简单查询字符串”查询来搜索它们。
数据样本(简化):
{"title":"U-12 Soccer",
"comment": "the t-shirts are dirty"}
由于已经有很多关于连字符的问题,我已经尝试了以下解决方案:
使用字符过滤器:ElasticSearch - Searching with hyphens in name。
所以我选择了这个映射:
{
"settings":{
"analysis":{
"char_filter":{
"myHyphenRemoval":{
"type":"mapping",
"mappings":[
"-=>"
]
}
},
"analyzer":{
"default":{
"type":"custom",
"char_filter": [ "myHyphenRemoval" ],
"tokenizer":"standard",
"filter":[
"standard",
"lowercase"
]
}
}
}
},
"mappings":{
"test":{
"properties":{
"title":{
"type":"string"
},
"comment":{
"type":"string"
}
}
}
}
}
使用以下查询完成搜索:
{"_source":true,
"query":{
"simple_query_string":{
"query":"<Text>",
"default_operator":"AND"
}
}
}
-
什么有效:
“U-12”、“U*”、“t*”、“ts*”
-
什么没用:
“U-*”、“u-1*”、“t-*”、“t-sh*”、...
所以看起来char过滤器没有在搜索字符串上执行? 我能做些什么来完成这项工作?
【问题讨论】:
标签: elasticsearch mapping hyphen