在处理用户的一个查询时,最初我以为他使用的是最新版本,当他显示分析API时,这是令人惊讶的。
需要为其检查令牌的自定义分析器
{
"settings": {
"analysis": {
"filter": {
"splcharfilter": {
"type": "pattern_capture",
"preserve_original": true,
"patterns": [
"([?/])"
]
}
},
"analyzer": {
"splcharanalyzer": {
"tokenizer": "keyword",
"filter": [
"splcharfilter",
"lowercase"
]
}
}
}
}
}
分析API
POST /_analyze
{
"analyzer": "splcharanalyzer",
"text" : "And/or"
}
Output
{
"tokens": [
{
"token": "analyzer", --> why this token
"start_offset": 7,
"end_offset": 15,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "splcharanalyzer", --> why this token
"start_offset": 19,
"end_offset": 34,
"type": "<ALPHANUM>",
"position": 2
},
{
"token": "text", --> why this token
"start_offset": 42,
"end_offset": 46,
"type": "<ALPHANUM>",
"position": 3
},
{
"token": "and",
"start_offset": 51,
"end_offset": 54,
"type": "<ALPHANUM>",
"position": 4
},
{
"token": "or",
"start_offset": 58,
"end_offset": 60,
"type": "<ALPHANUM>",
"position": 5
}
]
}
正如上面清楚显示的那样,它生成了许多不正确的令牌,当检查用户提到他使用的是1.7版本时,并遵循最新版本的elasticsearch中提供的语法。
由于Elasticsearch 1.X版本太旧了,默认情况下Elasticsearch打开最新版本的API,并想知道分析API对排除Elasticsearch中如此多问题的重要性,所以我在这里发布了1.X版本的正确语法,希望这会帮助Elasticsearch的其他旧版本用户。
可以在此处找到Elasticsearch 1.X分析API文档,以下是为问题中提到的文本生成的正确令牌。
GET /_analyze?analyzer=splcharanalyzer&text=And/or --> note its GET request
更正为And/or
问题1.X发布的分析器生成的令牌
{
"tokens": [
{
"token": "and/or",
"start_offset": 0,
"end_offset": 6,
"type": "word",
"position": 1
},
{
"token": "/",
"start_offset": 0,
"end_offset": 6,
"type": "word",
"position": 1
}
]
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句