【发布时间】:2019-07-25 08:26:27
【问题描述】:
我的弹性搜索索引中有一些 id 值(数字和文本组合),在我的程序中,用户可能会在搜索关键字中输入一些特殊字符。 而且我想知道无论如何可以让elasticsearch使用精确搜索并且还可以删除搜索关键字中的一些特殊字符
我已经使用自定义分析器通过一些特殊字符来分割搜索关键字。并使用 query->match 搜索数据,我仍然没有结果
- 数据
{
"_index": "testdata",
"_type": "_doc",
"_id": "11112222",
"_source": {
"testid": "1MK444750"
}
}
- 自定义分析器
"analysis" : {
"analyzer" : {
"testidanalyzer" : {
"pattern" : """([^\w\d]+|_)""",
"type" : "pattern"
}
}
}
- 映射
{
"article" : {
"mappings" : {
"_doc" : {
"properties" : {
"testid" : {
"type" : "text",
"analyzer" : "testidanalyzer"
}
}
}
}
}
}
这是我的弹性搜索查询
GET /testdata/_search
{
"query": {
"match": {
// "testid": "1MK_444-750" // no result
"testid": "1MK444750"
}
}
}
分析器成功分离了我的关键字,但我无法匹配结果中的任何内容
POST /testdata/_analyze
{
"analyzer": "testidanalyzer",
"text": "1MK_444-750"
}
{
"tokens" : [
{
"token" : "1mk",
"start_offset" : 0,
"end_offset" : 3,
"type" : "word",
"position" : 0
},
{
"token" : "444",
"start_offset" : 4,
"end_offset" : 7,
"type" : "word",
"position" : 1
},
{
"token" : "750",
"start_offset" : 8,
"end_offset" : 11,
"type" : "word",
"position" : 2
}
]
}
请帮忙,提前谢谢!
【问题讨论】:
标签: database elasticsearch search