【发布时间】:2015-03-16 02:41:20
【问题描述】:
我正在尝试设置一个电子邮件字段以在我的映射中正确索引。
因为我不希望 email 在被索引时被标记化,所以我之前指定了以下映射以允许它仅在整个字符串匹配时匹配搜索。
{
"users": {
"mappings": {
"user": {
"properties": {
"email": {
"type": "string",
"index": "not_analyzed"
},
"name": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"nickname": {
"type": "string"
}
}
}
}
}
}
除了我希望将 email 和 nickname 字段作为小写进行比较之外,此方法有效。
我尝试了几种方法来指定更改映射以使用小写标记过滤器。
我已经通过以下方式做到了这一点:
{
"settings":{
"index":{
"analysis":{
"analyzer":{
"lowercase_analyzer":{
"tokenizer":"standard", //Also tried 'Simple' and 'Keyword'
"filter":"lowercase"
}
}
}
}
},
"mappings": {
"user": {
"properties": {
"email": {
"type": "string",
"analyzer":"lowercase_analyzer",
"index": "not_analyzed" //Tried with and without this
},
"name": {
"type": "string",
"analyzer":"lowercase_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"nickname": {
"type": "string",
"analyzer": "lowercase_analyzer"
}
}
}
}
}
我希望允许以下行为:
- 电子邮件可以作为小写进行搜索和比较,并且只有在整个电子邮件匹配时才应该匹配
- name是多字段,用于搜索和排序,使用小写
- 昵称比较小写
【问题讨论】:
标签: mongodb elasticsearch mongoose elasticsearch-plugin