For storing categories, I have below schema -
{
name: String,
description : String,
subCategories:[
{
name:String,
description : String
}
]
}
For searching, need to apply atlas search index on both category name and subcategory name. I tried with the below mappings, it didn't work for subcategory's name and description.
{
"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"
}
}
}
}
Is there something I am missing in the field mappings?
Here is the working code to do Atlas search on document or Object.
mainSubscriber - > object (dataType)
The type of the main subscriber must be a 'document'. Then you can specify the inner field as below.
Refer to the static map example in the documentation for more details 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"
}
}
}
}
I found answer to this question of mine in this documentation for atlas search:
https://docs.atlas.mongodb.com/reference/atlas-search/index-definitions/
So, what I did referencing this document is, modified my mappings slightly to support what I expect. I was doing it in wrong manner earlier.
{
"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"
}
}
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.