【问题标题】:custom tokenizer without using built-in token filters不使用内置标记过滤器的自定义标记器
【发布时间】:2018-06-21 13:20:00
【问题描述】:

如何在不使用默认内置标记过滤器的情况下创建自定义标记器?例如:文本:“三星 Galaxy S9” 我想标记这个文本,以便它应该像这样被索引

["samsung", "galaxy", "s9", "samsung galaxy s9", "samsung s9", "samsung galaxy" , "galaxy s9"].

我该怎么做?

【问题讨论】:

    标签: elasticsearch tokenize


    【解决方案1】:
    PUT testindex
    {
      "settings": {
        "analysis": {
          "filter": {
            "filter_shingle": {
              "type": "shingle",
              "max_shingle_size": 20,
              "min_shingle_size": 2,
              "output_unigrams": "true"
            }
          },
          "analyzer": {
            "analyzer_shingle": {
              "tokenizer": "whitespace",
              "filter": [
                "lowercase",
                "filter_shingle"
              ]
            }
          }
        }
      },
      "mappings": {
        "product": {
          "properties": {
            "title": {
              "analyzer": "analyzer_shingle",
              "search_analyzer": "standard", 
              "type": "text"
            }
          }
        }
      }
    }
    
    POST testindex/product/1
    {
      "title": "Samsung Galaxy S9"
    }
    
    GET testindex/_analyze
    {
      "analyzer": "analyzer_shingle",
      "text": ["Samsung Galaxy S9"]
    }
    

    您可以找到更多关于带状疱疹的信息herehere

    第一个例子很棒,涵盖了很多内容。如果您想使用标准标记器而不是空格,那么您必须按照博客文章的描述处理停用词。两个url都是ES官方源

    【讨论】:

    • 但带状疱疹仅用于组合相邻的术语,但我想索引文本的单词排列。
    • 此外,Max-Min 之间的最大差异折旧为最大差异 3。#! Deprecation: Deprecated big difference between maxShingleSize and minShingleSize in Shingle TokenFilter,expected difference must be less than or equal to: [3]
    猜你喜欢
    • 2018-12-08
    • 2016-09-07
    • 2011-04-25
    • 2023-03-19
    • 2020-12-26
    • 2018-06-02
    • 1970-01-01
    • 2013-01-09
    • 2012-06-07
    相关资源
    最近更新 更多