【发布时间】:2017-10-22 10:28:20
【问题描述】:
这个问题是我之前的this SO 问题的延续。我有一些文本,我想在其上同时搜索数字和文本。
我的文字:-
8080.foobar.getFooLabelFrombar(test.java:91)
我想搜索getFooLabelFrombar、fooBar、8080 和91。
之前我使用simple 分析器,它将上面的文本标记为下面的标记。
"tokens": [
{
"token": "foobar",
"start_offset": 10,
"end_offset": 16,
"type": "word",
"position": 2
},
{
"token": "getfoolabelfrombar",
"start_offset": 17,
"end_offset": 35,
"type": "word",
"position": 3
},
{
"token": "test",
"start_offset": 36,
"end_offset": 40,
"type": "word",
"position": 4
},
{
"token": "java",
"start_offset": 41,
"end_offset": 45,
"type": "word",
"position": 5
}
]
}
其中,搜索 foobar 和 getFooLabelFrombar 给出了搜索结果,而不是 8080 和 91,因为 简单的分析器不会标记数字。 p>
然后按照前面的建议。 SO post,我将分析器更改为Standard,因此数字是可搜索的,但不是其他2字搜索字符串。由于标准分析器将创建以下标记:-
{
"tokens": [
{
"token": "8080",
"start_offset": 0,
"end_offset": 4,
"type": "<NUM>",
"position": 1
},
{
"token": "foobar.getfoolabelfrombar",
"start_offset": 5,
"end_offset": 35,
"type": "<ALPHANUM>",
"position": 2
},
{
"token": "test.java",
"start_offset": 36,
"end_offset": 45,
"type": "<ALPHANUM>",
"position": 3
},
{
"token": "91",
"start_offset": 46,
"end_offset": 48,
"type": "<NUM>",
"position": 4
}
]
}
我使用了 ES 中所有现有的分析器,但似乎没有任何东西能满足我的要求。我尝试创建下面的自定义分析器,但效果不佳。
{
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "letter"
"filter" : ["lowercase", "extract_numbers"]
}
},
"filter" : {
"extract_numbers" : {
"type" : "keep_types",
"types" : [ "<NUM>","<ALPHANUM>","word"]
}
}
}
}
请建议,我如何构建我的自定义分析器以满足我的要求。
【问题讨论】:
标签: elasticsearch tokenize elasticsearch-analyzers