Mongo db atlas search:在嵌入式文档上创建 atlas 搜索索引
Mongo db atlas search: create atlas search index on embedded document
为了存储类别,我有以下架构 -
{
name: String,
description : String,
subCategories:[
{
name:String,
description : String
}
]
}
对于搜索,需要在类别名称和子类别名称上应用图集搜索索引。我尝试了以下映射,它对子类别的名称和描述不起作用。
{
"mappings": {
"dynamic": false,
"fields": {
"name": {
"analyzer": "lucene.standard",
"type": "string"
},
"description": {
"analyzer": "lucene.standard",
"type": "string"
},
"subCategory.name": {
"analyzer": "lucene.standard",
"type": "string"
},
"subCategory.description": {
"analyzer": "lucene.standard",
"type": "string"
}
}
}
}
我在字段映射中遗漏了什么吗?
我在这个地图集搜索文档中找到了我这个问题的答案:
https://docs.atlas.mongodb.com/reference/atlas-search/index-definitions/
因此,我参考此文档所做的是,稍微修改我的映射以支持我的期望。我之前做错了。
{
"mappings": {
"dynamic": false,
"fields": {
"name": {
"analyzer": "lucene.standard",
"type": "string"
},
"description": {
"analyzer": "lucene.standard",
"type": "string"
},
"subCategory": {
"fields": {
"name": {
"analyzer": "lucene.standard",
"type": "string"
},
"description": {
"analyzer": "lucene.standard",
"type": "string"
}
}
}
}
}
}
这是对文档或对象进行 Atlas 搜索的工作代码。
mainSubscriber -> object (dataType)
主订阅者的类型必须是'document'。然后你可以指定内部字段如下。
更多细节请参考文档中的静态地图示例
https://docs.atlas.mongodb.com/reference/atlas-search/index-definitions#std-label-index-config-example
{
"mappings": {
"dynamic": false,
"fields": {
"identifier": {
"analyzer": "lucene.standard",
"type": "string"
},
"mainSubscriber": {
"fields": {
"identifier": {
"analyzer": "lucene.standard",
"type": "string"
}
},
"type": "document"
},
"profileId": {
"analyzer": "lucene.standard",
"type": "string"
}
}
}
}
为了存储类别,我有以下架构 -
{
name: String,
description : String,
subCategories:[
{
name:String,
description : String
}
]
}
对于搜索,需要在类别名称和子类别名称上应用图集搜索索引。我尝试了以下映射,它对子类别的名称和描述不起作用。
{
"mappings": {
"dynamic": false,
"fields": {
"name": {
"analyzer": "lucene.standard",
"type": "string"
},
"description": {
"analyzer": "lucene.standard",
"type": "string"
},
"subCategory.name": {
"analyzer": "lucene.standard",
"type": "string"
},
"subCategory.description": {
"analyzer": "lucene.standard",
"type": "string"
}
}
}
}
我在字段映射中遗漏了什么吗?
我在这个地图集搜索文档中找到了我这个问题的答案:
https://docs.atlas.mongodb.com/reference/atlas-search/index-definitions/
因此,我参考此文档所做的是,稍微修改我的映射以支持我的期望。我之前做错了。
{
"mappings": {
"dynamic": false,
"fields": {
"name": {
"analyzer": "lucene.standard",
"type": "string"
},
"description": {
"analyzer": "lucene.standard",
"type": "string"
},
"subCategory": {
"fields": {
"name": {
"analyzer": "lucene.standard",
"type": "string"
},
"description": {
"analyzer": "lucene.standard",
"type": "string"
}
}
}
}
}
}
这是对文档或对象进行 Atlas 搜索的工作代码。
mainSubscriber -> object (dataType)
主订阅者的类型必须是'document'。然后你可以指定内部字段如下。
更多细节请参考文档中的静态地图示例 https://docs.atlas.mongodb.com/reference/atlas-search/index-definitions#std-label-index-config-example
{
"mappings": {
"dynamic": false,
"fields": {
"identifier": {
"analyzer": "lucene.standard",
"type": "string"
},
"mainSubscriber": {
"fields": {
"identifier": {
"analyzer": "lucene.standard",
"type": "string"
}
},
"type": "document"
},
"profileId": {
"analyzer": "lucene.standard",
"type": "string"
}
}
}
}