自定义令牌生成器,而无需使用内置令牌过滤器

时间:2018-06-21 13:20:00

标签: elasticsearch tokenize

如何在不使用默认内置令牌过滤器的情况下创建自定义令牌生成器?例如:文字:“三星Galaxy S9” 我想标记此文本,以便应像这样

进行索引

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

我该怎么做?

1 个答案:

答案 0 :(得分:2)

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带状疱疹的更多信息

第一个例子很棒,它涵盖了很多内容。如果您要使用标准的分词器而不是空白,那么您将必须按照博客文章中的描述来处理停用词。这两个网址都是官方的ES来源