elasticsearch 自定义标记器 - 按长度拆分标记
elasticsearch custom tokenizer - split token by length
我正在使用 elasticsearch 版本 1.2.1。
我有一个用例,在该用例中,我想创建一个自定义分词器,该分词器将按其长度将分词打断到某个最小长度。例如,假设最小长度为 4,令牌 "abcdefghij" 将被拆分为:
"abcd efgh ij".
我想知道我是否可以在不需要编写自定义 Lucene Tokenizer 代码的情况下实现这个逻辑 class?
提前致谢。
根据您的要求,如果您无法做到这一点,请使用 pattern tokenizer then you'll need to code up a custom Lucene Tokenizer class yourself. You can create a custom Elasticsearch plugin for it. You can refer to this 有关如何为自定义分析器创建 Elasticsearch 插件的示例。
Pattern Tokenizer 支持一个参数"group"
它有一个默认值“-1”,这意味着使用模式进行拆分,这就是您所看到的。
然而,通过在你的模式中定义一个 >= 0 的组并设置组参数,这是可以做到的!例如。以下标记器会将输入拆分为 4 个字符的标记:
PUT my_index
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "pattern",
"pattern": "(.{4})",
"group": "1"
}
}
}
}
}
正在通过以下方式分析文档:
POST my_index/_analyze
{
"analyzer": "my_analyzer",
"text": "comma,separated,values"
}
产生以下标记:
{
"tokens": [
{
"token": "comm",
"start_offset": 0,
"end_offset": 4,
"type": "word",
"position": 0
},
{
"token": "a,se",
"start_offset": 4,
"end_offset": 8,
"type": "word",
"position": 1
},
{
"token": "para",
"start_offset": 8,
"end_offset": 12,
"type": "word",
"position": 2
},
{
"token": "ted,",
"start_offset": 12,
"end_offset": 16,
"type": "word",
"position": 3
},
{
"token": "valu",
"start_offset": 16,
"end_offset": 20,
"type": "word",
"position": 4
}
]
}
我正在使用 elasticsearch 版本 1.2.1。 我有一个用例,在该用例中,我想创建一个自定义分词器,该分词器将按其长度将分词打断到某个最小长度。例如,假设最小长度为 4,令牌 "abcdefghij" 将被拆分为: "abcd efgh ij".
我想知道我是否可以在不需要编写自定义 Lucene Tokenizer 代码的情况下实现这个逻辑 class?
提前致谢。
根据您的要求,如果您无法做到这一点,请使用 pattern tokenizer then you'll need to code up a custom Lucene Tokenizer class yourself. You can create a custom Elasticsearch plugin for it. You can refer to this 有关如何为自定义分析器创建 Elasticsearch 插件的示例。
Pattern Tokenizer 支持一个参数"group"
它有一个默认值“-1”,这意味着使用模式进行拆分,这就是您所看到的。
然而,通过在你的模式中定义一个 >= 0 的组并设置组参数,这是可以做到的!例如。以下标记器会将输入拆分为 4 个字符的标记:
PUT my_index
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "pattern",
"pattern": "(.{4})",
"group": "1"
}
}
}
}
}
正在通过以下方式分析文档:
POST my_index/_analyze
{
"analyzer": "my_analyzer",
"text": "comma,separated,values"
}
产生以下标记:
{
"tokens": [
{
"token": "comm",
"start_offset": 0,
"end_offset": 4,
"type": "word",
"position": 0
},
{
"token": "a,se",
"start_offset": 4,
"end_offset": 8,
"type": "word",
"position": 1
},
{
"token": "para",
"start_offset": 8,
"end_offset": 12,
"type": "word",
"position": 2
},
{
"token": "ted,",
"start_offset": 12,
"end_offset": 16,
"type": "word",
"position": 3
},
{
"token": "valu",
"start_offset": 16,
"end_offset": 20,
"type": "word",
"position": 4
}
]
}