elasticsearch:是否可以使用模式分词器发出重叠的分词?

elastcsearch : is it possible to emit overlapping tokens with the pattern tokenizer?

使用 elasticsearch,我想设置一个分析器来发出给定输入字符串的重叠标记,有点像边缘 Ngrams 标记器。 给定输入

a/b/c

我希望分析器产生令牌

a a/b a/b/c

我尝试了以下设置的模式分词器:

settings: {
  analysis: {
    tokenizer: {
      "my_tokenizer": {
        "type": "pattern",
        "pattern": "^(.*)(/|$)",
        "group": 1
       }
...

然而它并没有输出所有的匹配序列,因为它是贪心的只会输出

a/b/c

有什么方法可以使用内置 tokenizers/filters/analyzers 的另一种组合来做到这一点?

根据您的值格式,您可以使用 path hierarchy 分词器。

尝试分析 API :

GET _analyze?tokenizer=path_hierarchy&text=a/b/c

输出与您想要的非常接近:

{
   "tokens": [
      {
         "token": "a",
         "start_offset": 0,
         "end_offset": 1,
         "type": "word",
         "position": 1
      },
      {
         "token": "a/b",
         "start_offset": 0,
         "end_offset": 3,
         "type": "word",
         "position": 1
      },
      {
         "token": "a/b/c",
         "start_offset": 0,
         "end_offset": 5,
         "type": "word",
         "position": 1
      }
   ]
}

试一试,让我们知道:)