默认情况下,带有英语分析器的 Elasticsearch 会分解at&t
为 tokens at
,t
然后at
作为停用词删除。
POST _analyze
{
"analyzer": "english",
"text": "A word AT&T Procter&Gamble"
}
结果令牌看起来像:
{
"tokens" : [
{
"token" : "word",
"start_offset" : 2,
"end_offset" : 6,
"type" : "<ALPHANUM>",
"position" : 1
},
{
"token" : "t",
"start_offset" : 10,
"end_offset" : 11,
"type" : "<ALPHANUM>",
"position" : 3
},
{
"token" : "procter",
"start_offset" : 12,
"end_offset" : 19,
"type" : "<ALPHANUM>",
"position" : 4
},
{
"token" : "gambl",
"start_offset" : 20,
"end_offset" : 26,
"type" : "<ALPHANUM>",
"position" : 5
}
]
}
我希望能够精确匹配at&t
,同时能够procter&gamble
精确搜索并且能够搜索例如 only procter
。
所以我想构建一个分析器,它
为字符串
at&t
和, ,为.t
at&t
procter
gambl
procter&gamble
procter&gamble
有没有办法创建这样的分析器?或者我应该创建 2 个索引字段 - 一个用于常规英语分析器,另一个用于English except tokenization by &
?