Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb atlas搜索:应用多语言分析器_Mongodb_Mongodb Atlas_Mongodb Atlas Search - Fatal编程技术网

Mongodb atlas搜索:应用多语言分析器

Mongodb atlas搜索:应用多语言分析器,mongodb,mongodb-atlas,mongodb-atlas-search,Mongodb,Mongodb Atlas,Mongodb Atlas Search,有一个集合,即-categories,它具有以下模式 { name: String, language: { $type: String, default: "de"} translation:[ { language: { $type: String, enum: ["en","fr"]}, name:String } ] } 它有特定

有一个集合,即-categories,它具有以下模式

{
    name: String,
    language: { $type: String, default: "de"}
    translation:[
      {
          language: { $type: String, enum: ["en","fr"]}, 
          name:String
      }
    ]
}
它有特定于语言的数据,而不是名称太像描述等。我想为所有三种语言的名称字段创建atlas搜索索引。我曾尝试使用'name''translation.name'创建atlas搜索索引,但对translation.name无效。以下是atlas搜索索引:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "name": {
        "analyzer": "lucene.german",
        "type": "string"
      },
      "translation.name": {
        "analyzer": "lucene.french",
        "type": "string"
      }
    }
}

这里的问题是,如果我将language analyzer指定为translation.name作为德语,我就不能将其应用于英语。如何将多个语言分析器用于单个字段?

在atlas search的索引定义文档中,我找到了查询的答案,即为单个字段应用多个语言分析器。这里是文档的链接-

这就是我将映射修改为:

{
  "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"
              }
            }
          }
        }
      }
    }
  }
}