user4697008
user4697008

Reputation:

Atlas Search Autocomplete on Subdocument Array

I am having some trouble with the autocomplete atlas search data type when trying to define an index for an array of subdocuments in my document.

My data structure for the documents in my collection looks like this:

{
   "data": {
     "equipment": {
       "entries": [
         {
           "name": "abcdefg"
         }
         {
           "name": "hijklmno"
         }
       ]
     }
   }
}

When I define a string index for searching the entries array, it works as intended and I get logical results. Here is my index definition using the lucene.keyword analyzer:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "data": {
        "fields": {
          "equipment": {
            "fields": {
              "entries": {
                "fields": {
                  "name": {
                    "analyzer": "lucene.keyword",
                    "searchAnalyzer": "lucene.keyword",
                    "type": "string"
                  }
                },
                "type": "document"
              }
            },
            "type": "document"
          }
        },
        "type": "document"
      }
    }
  }
}

However, when I try the same thing with the autocomplete type, I get an empty result, but no error. Here is how I defined the autocomplete:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "data": {
        "fields": {
          "equipment": {
            "fields": {
              "entries": {
                "fields": {
                  "name": {
                    "tokenization": "nGram",
                    "type": "autocomplete"
                  }
                },
                "type": "document"
              }
            },
            "type": "document"
          }
        },
        "type": "document"
      }
    }
  }
}

The documentation for Atlas Search states the following: The autocomplete type can't be used to index fields whose value is an array of strings. So either this sentence has to be changed to say all kinds of arrays or I am doing something wrong here. Can someone clarify if this is even possible? Thanks in Advance

Upvotes: 0

Views: 1195

Answers (1)

Stone
Stone

Reputation: 291

Your syntax is completely wrong. its would be like:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "data.equipment.entries.name": [
        {
          "type": "autocomplete",
          "tokenization": "nGram",
          "minGrams": 3,
          "maxGrams": 7,
        }
      ]
    }
  }
}

But I am not sure that,if it support on array of document, But let me know if your problem is solved.

Upvotes: 0

Related Questions