Allow autocomplete on nested document field
Although I can index a nested field using the autocomplete type, it does not return any results when queried.
Here's an example snippet from an index definiton:
"Customers": {
"dynamic": false,
"fields": {
"Name": {
"foldDiacritics": true,
"maxGrams": 8,
"minGrams": 3,
"type": "autocomplete"
}
},
"type": "document"
},
In the above example, for a customer named "John Smith" I'd expect to get a result for "joh" when querying on the Customer.Name path. But I currently get no results.
-
Jakub Barchiewicz commented
This is marked as complete but actually it's not. At least not fully. Considering Customers is an array of documents, it should be provided with `embeddedDocuments` type. And when using embeddedDocuments, highlights are not supported. You can find something, but you don't know what has been found.
-
Roy commented
I tried replicating your setup and it seems to work fine -- using an M0 cluster (5.0.6), the collection is named "test" and contains one document as follows:
{
"_id": {
"$oid": "6223fb6bf163ae81ad95acd9"
},
"Customers":{
"Name": "John Smith"
}}My search index definition is as follows:
{
"mappings": {
"dynamic": false,
"fields": {
"Customers": {
"dynamic": false,
"fields": {
"Name": {
"foldDiacritics": true,
"maxGrams": 8,
"minGrams": 3,
"type": "autocomplete"
}
},
"type": "document"
}
}
}
}My aggregation pipeline is:
[
{
"$search": {
"index": "test",
"autocomplete": {
"query": "joh",
"path": "Customers.Name"
}
}
}
]This returns the document as expected