Link Search Menu Expand Document Documentation Menu

西班牙语分析器

内置的 spanish 分析器可以通过以下命令应用于文本字段

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

词干排除

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

PUT index_with_stem_exclusion_spanish_analyzer
{
  "settings": {
    "analysis": {
      "analyzer": {
        "stem_exclusion_spanish_analyzer": {
          "type": "spanish",
          "stem_exclusion": ["autoridad", "aprobación"]
        }
      }
    }
  }
}

西班牙语分析器内部结构

spanish 分析器由以下组件构建

  • 分词器:standard

  • 词元过滤器

    • 小写
    • 停用词 (西班牙语)
    • 关键词
    • 词干提取器 (西班牙语)

自定义西班牙语分析器

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

PUT /spanish-index
{
  "settings": {
    "analysis": {
      "filter": {
        "spanish_stop": {
          "type": "stop",
          "stopwords": "_spanish_"
        },
        "spanish_stemmer": {
          "type": "stemmer",
          "language": "light_spanish"
        },
        "spanish_keywords": {
          "type": "keyword_marker",
          "keywords": []
        }
      },
      "analyzer": {
        "spanish_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "spanish_stop",
            "spanish_keywords",
            "spanish_stemmer"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "spanish_analyzer"
      }
    }
  }
}

生成的词元

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

POST /spanish-index/_analyze
{
  "field": "content",
  "text": "Los estudiantes estudian en universidades españolas. Sus números son 123456."
}

响应包含生成的词元

{
  "tokens": [
    {
      "token": "estudiant",
      "start_offset": 4,
      "end_offset": 15,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "estudian",
      "start_offset": 16,
      "end_offset": 24,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "universidad",
      "start_offset": 28,
      "end_offset": 41,
      "type": "<ALPHANUM>",
      "position": 4
    },
    {
      "token": "español",
      "start_offset": 42,
      "end_offset": 51,
      "type": "<ALPHANUM>",
      "position": 5
    },
    {
      "token": "numer",
      "start_offset": 57,
      "end_offset": 64,
      "type": "<ALPHANUM>",
      "position": 7
    },
    {
      "token": "123456",
      "start_offset": 69,
      "end_offset": 75,
      "type": "<NUM>",
      "position": 9
    }
  ]
}
剩余 350 字符

有问题?

想要贡献?