2

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?

2 Answers 2

1

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"
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.