【问题标题】:elastcsearch : is it possible to emit overlapping tokens with the pattern tokenizer?elasticsearch:是否可以使用模式标记器发出重叠标记?
【发布时间】:2015-01-27 14:54:50
【问题描述】:

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

a/b/c

我希望分析器生成令牌

a a/b a/b/c

我使用以下设置尝试了模式标记器:

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

但是它不会输出所有匹配的序列,因为它是贪婪的,所以只会输出

a/b/c

有没有办法通过内置标记器/过滤器/分析器的另一种组合来做到这一点?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    根据您的值格式,您可以使用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
          }
       ]
    }
    

    试一试,然后告诉我们:)

    【讨论】:

    • 奇怪的是,那个确切的请求给了我标记“a”、“b”和“c”,但文档同意你的回答;我的 elasticsearch 版本必须是 borked,必须升级...
    • 好的,使用 PathHierarchy 标记器定义自定义分析器是可行的。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-09
    • 2018-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    相关资源
    最近更新 更多