mongodbmongodb-atlasmongodb-atlas-search

MongoDB Atlas Search Definition JSON - String arrays


I have an object like this in a collection in my MongoDB Atlas:

{
  "outer" : {
     "tags" : [
        "astring",
        "another string",
        ...
     ],
     ...
  }
  ...
}

Now I wish to make an index on the array outer.tags among other things. I have made the index definition like this:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "outer": {
        "dynamic": false,
        "fields": {
          "tags": {
            "dynamic": true
          }
        }
        ...
      }
      ...
    }
  }
}

But I still can't search inside tag, how should I change the definition so to be able to do so?


Solution

  • It was fixed by simply this:

    {
      "mappings": {
        "dynamic": false,
        "fields": {
          "outer": {
            "dynamic": false,
            "fields": {
              "tags": {
                "analyzer": "lucene.simple",
                "searchAnalyzer": "lucene.simple",
                "type": "string"
              }
            }
            ...
          }
          ...
        }
      }
    }