当根据 7.X 语法使用时,Elasticsearch analyze API 显示带有 1.X 版本的错误标记
Elasticsearch analyze API shows wrong tokens with 1.X version when used according to 7.X syntax
在处理用户的一个查询时,最初我假设他使用的是最新版本,当他显示 analyze 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 中这么多问题的重要性 I我在这里发布 1.X 版本的正确语法,希望这对 Elasticsearch 的其他旧版本用户有所帮助。
可以找到 Elasticsearch 1.X 分析 API 文档 here 以下是为问题中提到的文本生成的正确标记。
GET /_analyze?analyzer=splcharanalyzer&text=And/or --> note its GET request
使用针对 1.X
发布的分析器更正为 And/or
生成的令牌
{
"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
}
]
}
在处理用户的一个查询时,最初我假设他使用的是最新版本,当他显示 analyze 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 中这么多问题的重要性 I我在这里发布 1.X 版本的正确语法,希望这对 Elasticsearch 的其他旧版本用户有所帮助。
可以找到 Elasticsearch 1.X 分析 API 文档 here 以下是为问题中提到的文本生成的正确标记。
GET /_analyze?analyzer=splcharanalyzer&text=And/or --> note its GET request
使用针对 1.X
发布的分析器更正为And/or
生成的令牌
{
"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
}
]
}