Link Search Menu Expand Document Documentation Menu

英语分析器

内置的 english 分析器可以使用以下命令应用于文本字段

PUT /english-index
{
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "english"
      }
    }
  }
}

词干排除

您可以使用以下命令将 stem_exclusion 与此语言分析器一起使用

PUT index_with_stem_exclusion_english_analyzer
{
  "settings": {
    "analysis": {
      "analyzer": {
        "stem_exclusion_english_analyzer": {
          "type": "english",
          "stem_exclusion": ["authority", "authorization"]
        }
      }
    }
  }
}

英语分析器内部结构

english 分析器由以下组件构建

  • 分词器:standard

  • 词元过滤器

    • 词干提取器 (possessive_english)
    • 小写
    • 停用词 (英语)
    • 关键词
    • 词干提取器 (英语)

自定义英语分析器

您可以使用以下命令创建自定义英语分析器

PUT /english-index
{
  "settings": {
    "analysis": {
      "filter": {
        "english_stop": {
          "type": "stop",
          "stopwords": "_english_"
        },
        "english_stemmer": {
          "type": "stemmer",
          "language": "english"
        },
        "english_keywords": {
          "type": "keyword_marker",
          "keywords": []
        },
        "english_possessive_stemmer": {
          "type":       "stemmer",
          "language":   "possessive_english"
        }
      },
      "analyzer": {
        "english_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "english_possessive_stemmer",
            "lowercase",
            "english_stop",
            "english_keywords",
            "english_stemmer"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "english_analyzer"
      }
    }
  }
}

生成的词元

使用以下请求检查使用该分析器生成的词元

POST /english-index/_analyze
{
  "field": "content",
  "text": "The students study in the USA and work at NASA. Their numbers are 123456."
}

响应包含生成的词元

{
  "tokens": [
    {"token": "student","start_offset": 4,"end_offset": 12,"type": "<ALPHANUM>","position": 1},
    {"token": "studi","start_offset": 13,"end_offset": 18,"type": "<ALPHANUM>","position": 2},
    {"token": "usa","start_offset": 26,"end_offset": 29,"type": "<ALPHANUM>","position": 5},
    {"token": "work","start_offset": 34,"end_offset": 38,"type": "<ALPHANUM>","position": 7},
    {"token": "nasa","start_offset": 42,"end_offset": 46,"type": "<ALPHANUM>","position": 9},
    {"token": "number","start_offset": 54,"end_offset": 61,"type": "<ALPHANUM>","position": 11},
    {"token": "123456","start_offset": 66,"end_offset": 72,"type": "<NUM>","position": 13}
  ]
}
剩余 350 字符

有问题?

想要贡献?