Unique 词元过滤器
Unique 词元过滤器可确保在分析过程中只保留唯一的词元,从而删除在单个字段或文本块中出现的重复词元。
参数
Unique 词元过滤器可以通过以下参数进行配置。
参数 | 必需/可选 | 数据类型 | 描述 |
---|---|---|---|
only_on_same_position | 可选 | 布尔型 | 如果为 true ,则该词元过滤器将作为 remove_duplicates 词元过滤器,并且只删除位于相同位置的词元。默认为 false 。 |
示例
以下示例请求创建了一个名为 unique_example
的新索引,并配置了一个带有 unique
过滤器的分析器
PUT /unique_example
{
"settings": {
"analysis": {
"filter": {
"unique_filter": {
"type": "unique",
"only_on_same_position": false
}
},
"analyzer": {
"unique_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"unique_filter"
]
}
}
}
}
}
生成的词元
使用以下请求检查使用该分析器生成的词元
GET /unique_example/_analyze
{
"analyzer": "unique_analyzer",
"text": "OpenSearch OpenSearch is powerful powerful and scalable"
}
响应包含生成的词元
{
"tokens": [
{
"token": "opensearch",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "is",
"start_offset": 22,
"end_offset": 24,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "powerful",
"start_offset": 25,
"end_offset": 33,
"type": "<ALPHANUM>",
"position": 2
},
{
"token": "and",
"start_offset": 43,
"end_offset": 46,
"type": "<ALPHANUM>",
"position": 3
},
{
"token": "scalable",
"start_offset": 47,
"end_offset": 55,
"type": "<ALPHANUM>",
"position": 4
}
]
}