elasticsearch - 根据 7.X 语法使用时,Elasticsearch 分析 API 显示 1.X 版本的错误令牌
问题描述
在处理用户的一个查询时,最初我认为他使用的是最新版本,而当他显示分析 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
}
]
}
推荐阅读
- javascript - 富文本编辑器只允许简单的格式,如粗体和链接,即使在粘贴时也是如此
- python - 在该循环中迭代的更改列表
- spring-data-jpa - 如何使用 Spring JPA 在没有 Spring 干预的情况下使用真正自定义的存储库
- vba - 控制源上的 IF 语句
- python - Anaconda3 在安装 Tensorflow 时出现问题
- azure - Azure 函数自定义身份验证
- java - 无法在 Spring 中写入属性文件
- java - RxJava 使用优化请求
- android - 在Android中上下滑动更改布局
- .net - GetHostEntry 的结果与 nslookup 不同