Mongodb atlas search: 应用多语言分析器
Mongodb atlas search: apply multiple language analyzers
有一个集合——类别,它有以下架构
{
name: String,
language: { $type: String, default: "de"}
translation:[
{
language: { $type: String, enum: ["en","fr"]},
name:String
}
]
}
它有特定于语言的数据,除了名字太像-描述等等。我想在所有三种语言的名称字段上创建图集搜索索引。我尝试使用 'name' 和 'translation.name' 创建图集搜索索引,但它不适用于 translation.name.这是图集搜索索引:
{
"mappings": {
"dynamic": false,
"fields": {
"name": {
"analyzer": "lucene.german",
"type": "string"
},
"translation.name": {
"analyzer": "lucene.french",
"type": "string"
}
}
}
这里的问题是,如果我将 translation.name 的语言分析器指定为德语,则我无法将其应用于英语。多个语言分析器如何用于单个字段?
在 atlas 搜索的索引定义文档中,我找到了查询的答案,即为单个字段应用多种语言分析器。这是文档的 link -
https://docs.atlas.mongodb.com/reference/atlas-search/index-definitions/
这就是我将映射修改为:
{
"mappings": {
"dynamic": false,
"fields": {
"name": {
"analyzer": "lucene.german",
"type": "string"
},
"translation": {
"type": "document",
"fields": {
"name": {
"multi": {
"english": { //english is the name that I have given to this analyzer
"analyzer": "lucene.english",
"type": "string"
},
"french": { //french is the name that I have given to this analyzer
"analyzer": "lucene.french",
"type": "string"
}
}
}
}
}
}
}
}
有一个集合——类别,它有以下架构
{
name: String,
language: { $type: String, default: "de"}
translation:[
{
language: { $type: String, enum: ["en","fr"]},
name:String
}
]
}
它有特定于语言的数据,除了名字太像-描述等等。我想在所有三种语言的名称字段上创建图集搜索索引。我尝试使用 'name' 和 'translation.name' 创建图集搜索索引,但它不适用于 translation.name.这是图集搜索索引:
{
"mappings": {
"dynamic": false,
"fields": {
"name": {
"analyzer": "lucene.german",
"type": "string"
},
"translation.name": {
"analyzer": "lucene.french",
"type": "string"
}
}
}
这里的问题是,如果我将 translation.name 的语言分析器指定为德语,则我无法将其应用于英语。多个语言分析器如何用于单个字段?
在 atlas 搜索的索引定义文档中,我找到了查询的答案,即为单个字段应用多种语言分析器。这是文档的 link -
https://docs.atlas.mongodb.com/reference/atlas-search/index-definitions/
这就是我将映射修改为:
{
"mappings": {
"dynamic": false,
"fields": {
"name": {
"analyzer": "lucene.german",
"type": "string"
},
"translation": {
"type": "document",
"fields": {
"name": {
"multi": {
"english": { //english is the name that I have given to this analyzer
"analyzer": "lucene.english",
"type": "string"
},
"french": { //french is the name that I have given to this analyzer
"analyzer": "lucene.french",
"type": "string"
}
}
}
}
}
}
}
}