实现它的一种方法是创建另一个没有lowercase
标记过滤器的分析器,并在主字段的子字段上使用该分析器。它是这样的:
使用两个分析器tight
和tight_acronym
. 前者分配给 the field
,后者分配给field.acronyms
子字段:
PUT index
{
"settings": {
"analysis": {
"analyzer": {
"tight": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"asciifolding"
]
},
"tight_acronym": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"asciifolding"
]
}
}
}
},
"mappings": {
"test": {
"properties": {
"field": {
"type": "string",
"analyzer": "tight",
"fields": {
"acronyms": {
"type": "string",
"analyzer": "tight_acronym"
}
}
}
}
}
}
}
然后我们索引两个文档:
PUT index/test/1
{ "field": "It is worth CAN 300" }
PUT index/test/2
{ "field": "can you do it?" }
然后,如果您搜索CAN
(在子字段上),您将获得第一个文档
POST index/test/_search
{
"query": {
"match": {
"field.acronyms": "CAN"
}
}
}
如果您搜索can
(在主字段上),您将获得第二个文档
POST index/test/_search
{
"query": {
"match": {
"field": "can"
}
}
}