保留类型分词过滤器
keep_types 分词过滤器是一种用于文本分析以控制保留或丢弃哪些分词类型的过滤器。不同的分词器会产生不同的分词类型,例如 <HOST>、<NUM> 或 <ALPHANUM>。
keyword、simple_pattern 和 simple_pattern_split 分词器不支持 keep_types 分词过滤器,因为这些分词器不支持分词类型属性。
参数
keep_types 分词过滤器可以使用以下参数进行配置。
| 参数 | 必需/可选 | 数据类型 | 描述 |
|---|---|---|---|
types | 必需 | 字符串列表 | 要保留或丢弃的分词类型列表(由 mode 确定)。 |
mode | 可选 | 字符串 | 是包含还是排除 types 中指定的分词类型。默认为 include。 |
示例
以下示例请求创建一个名为 test_index 的新索引,并配置一个带有 keep_types 过滤器的分析器
PUT /test_index
{
"settings": {
"analysis": {
"analyzer": {
"custom_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": ["lowercase", "keep_types_filter"]
}
},
"filter": {
"keep_types_filter": {
"type": "keep_types",
"types": ["<ALPHANUM>"]
}
}
}
}
}
生成的词元
使用以下请求检查使用该分析器生成的词元
GET /test_index/_analyze
{
"analyzer": "custom_analyzer",
"text": "Hello 2 world! This is an example."
}
响应包含生成的词元
{
"tokens": [
{
"token": "hello",
"start_offset": 0,
"end_offset": 5,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "world",
"start_offset": 8,
"end_offset": 13,
"type": "<ALPHANUM>",
"position": 2
},
{
"token": "this",
"start_offset": 15,
"end_offset": 19,
"type": "<ALPHANUM>",
"position": 3
},
{
"token": "is",
"start_offset": 20,
"end_offset": 22,
"type": "<ALPHANUM>",
"position": 4
},
{
"token": "an",
"start_offset": 23,
"end_offset": 25,
"type": "<ALPHANUM>",
"position": 5
},
{
"token": "example",
"start_offset": 26,
"end_offset": 33,
"type": "<ALPHANUM>",
"position": 6
}
]
}